Direction of Velocity

Discussion in 'Plugin Development' started by Domeax, Sep 23, 2016.

Thread Status:
Not open for further replies.
  1. I have one certain position. The other position is the position of the player.

    When the player is doing something i want to knock him to the other direction as the direction of the certain position.

    I hope the drawing can help.
     
  2. Offline

    CraftCreeper6

    @Domeax
    Have you tried anything? Additionally, I'm not quite sure what your image is telling me.
     
  3. Offline

    Whoneedspacee

    You want to go the opposite of the vector between the your position and position1, so you get the vector between you and position 1, then just reverse it, multiply it, and apply it to the player.

    Edit : I recommend looking at this if you get lost -
    https://bukkit.org/threads/tutorial-how-to-calculate-vectors.138849/
    Specifically section 4.2
     
    Last edited: Sep 23, 2016
  4. Offline

    mythbusterma

    @Domeax

    1. Take player's position, and subtract from it the position you'd like to move away from
    2. Normalise the resultant vector
    3. Multiply it by the speed you'd like the player to have
    4. Set the player's velocity to this.
     
  5. Offline

    Evonoucono

    @Domeax
    Try this:
    Code:
    PLAYER.setVelocity(LOCATION.toVector().subtract(PLAYER.getLocation().toVector()).normalize().multiply(STRENGTH));
    It should send the player towards the specified location while strength is simply how fast the initial push will be.
     
Thread Status:
Not open for further replies.

Share This Page