# Solved Change head rotation of EntityPlayer

Discussion in 'Spigot Plugin Development' started by Mr.Midnight, May 14, 2016.

1. ### Mr.Midnight

How can I set the yaw and pitch of an EntityPlayer?

2. ### JacobCrofts

Like so:
Code (Text):
someEntity.teleport(someEntity.getLocation().setDirection(someVector));

3. ### Mr.Midnight

Teleport doesn't do anything to custom EntityPlayers.

4. ### JacobCrofts

Ah, I misread. I printed out all the methods associated with EntityPlayer, and this one (from a superclass) looks promising:

net.minecraft.server.v1_9_R2.Entity net.minecraft.server.v1_9_R2.Entity.teleportTo(org.bukkit.Location,boolean)

• Informative x 1
5. ### Mr.Midnight

I will try it in a bit ^-^. But off to the next problem, I am giving the EntityPlayer velocity using EntityPlayer#move(x, y, z); , But I want the yaw and pitch to match the moving player whilst moving.

6. ### Leniency

Try using just location.
Code (Text):
Location l = p.getLocation();
l.setYaw(6);
l.setPitch(7);
p.teleport(l);
?

7. ### j0ach1mmall3

setPositionRotation IIRC

8. ### JacobCrofts

Yaw/pitch information can be derived from a Vector. It would be wrong to claim that a Vector is the the same as yaw/pitch, since vectors have magnitude as well as direction, but changing the direction a player is facing disregards this magnitude and only considers the direction.

I think all you need to do is find the direction a player is moving (Entity#getVelocity(), and probably something similar for EntityPlayer) and assign that direction to the player's Location (as a Vector!) using the teleport command I described above.

9. ### Mr.Midnight

Problem is, the move() only takes x, y, z

10. ### CryptedFormula

Did you fix this already? If not, you can set the pitch/yaw of an EntityPlayer using the following:

Code (Text):
entityPlayer.pitch = pitch;
entityPlayer.lastPitch = pitch;
entityPlayer.yaw = yaw;
entityPlayer.lastYaw = yaw;
entityPlayer.aQ = yaw;
entityPlayer.aR = yaw;
entityPlayer.aO = yaw;
entityPlayer.aP = yaw;

• Useful x 1
11. ### Mr.Midnight

I haven't been messing with NPC's recently, but this could be useful for future reference, thank you <3 :3

• Like x 1