Solved Flipping player direction

Discussion in 'Spigot Plugin Development' started by Chemi, Jul 2, 2015.

  1. I'm trying to teleport a plugin behind a player and set his direction to the player he teleported to.
    I have no idea how to "flip" the direction (set the direction to the location of player you right clicked)
     
  2. sothatsit

    Patron

    Player.getEyeLocation().getDirection().multiply(-1)
     
    • Agree Agree x 1
  3. Serializator

    Supporter

    Make sure you do ".add" instead of ".substract" and don't add the direction but add the 'X' and 'Z' locations from the direction and set 'Y' to 0, else the player will be teleported one block in the air.
     
  4. or you can just get the location of the playerToTeleport and set his yaw and pitch to the other player's yaw and pitch.
    For teleporting them behind a player i have a little snippet here that i used quite a while ago:

    PHP:
                Vector direction = d.getLocation().getDirection().normalize();
                direction.multiply(-2);
                p.teleport(d.getLocation().add(direction));
    EDIT: this will teleport the player 2 blocks behind the other i think, to modify the distance you'd change the -2
     
  5. You don't need to normalize, because the direction is I think already normalized. Just a small performance increase if it's called a lot of times.
     
  6. Thanks for the help everyone, It worked :)
     
  7. Please mark the thread as solved, to inform other people.