[Solved]Add certain velocity on a player

Discussion in 'Plugin Development' started by Jobi, Apr 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Jobi

    Hello,

    In my plugin i must push a player away, when someone rightklicks him. this is not the problem, but i don' t know how to push im in the direktion where the player is looking at(right preposition??), because that would look logical. I know that i can push player in a direction with player.setVelocity(vector), but how can i convert the yaw and the pitch from the right-clicking player into a vector?

    JoBi9
     
  2. Offline

    ItsHarry

    Idk how old you are and if you had this in school yet, but you can use a triangle to calculate the gradient using either pytahgoras or sohcahtoa.
     
  3. Offline

    Father Of Time

    Or simply use the getDirection() function of the LivingEntity class, it does it for you. :D

    The get direction function returns a vector that is the exact trajectory of the entity it's used on, AKA it will return a vector that represents that yaw and pitch of the entity you use it on.

    Hope this helps!
     
  4. Offline

    Jobi

    Can you give me an example?
    Ok, i did it:

    Code:
    Entity entity = event.getRightClicked();   
    Vector vector = player.getLocation().getDirection().setX(player.getLocation().getDirection().getX() + 1).setY(player.getLocation().getDirection().getX() + 0.5).setZ(player.getLocation().getDirection().getZ() + 1);
    entity.setVelocity(vector);
            
     
Thread Status:
Not open for further replies.

Share This Page