How to get the direction the player is facing?

Discussion in 'Plugin Development' started by DirtyStarfish, Sep 25, 2011.

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

    DirtyStarfish

    Hey

    I'm trying to learn about teleporting players and so far its been going well. The problem I'm having is that the player will teleport, but change the direction they were facing. I assume they are automatically being turned to face north.

    So, I'm able to get the player to the right location, but how do I get them to still face the same direction as they were before?

    This is the code I use to actually teleport the player. But what would I add to keep them facing the same way?
    Code:
    player.teleport(new Location(player.getWorld(),x,y + 1,z));
     
  2. You have to include the Yaw and Pitch.
    You can get them by using player.getLocation().getYaw() and player.getLocation().getPitch()
    and when constructing the new location, you add those two values aswell
    new Location(player.getWorld(),x,y + 1,z), Yaw, Pitch);
     
    saxissweet and DirtyStarfish like this.
  3. Offline

    DirtyStarfish

    Code:
    new Location(player.getWorld(),x,y + 1,z), Yaw, Pitch);
    Oh, Eclipse doesn't like this!

    Even if I set the players Pitch and Yaw after the teleport it doesn't do anything..

    EDIT: Got it working!

    This is the code I used:
    Code:
    player.teleport(new Location(player.getWorld(), x, y + 1, z, yaw, pitch));
    Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page