Solved Change head rotation of EntityPlayer

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

  1. How can I set the yaw and pitch of an EntityPlayer?
     
  2. Like so:
    Code (Text):
    someEntity.teleport(someEntity.getLocation().setDirection(someVector));
     
  3. Teleport doesn't do anything to custom EntityPlayers.
     
  4. 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 Informative x 1
  5. 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. Try using just location.
    Code (Text):
    Location l = p.getLocation();
    l.setYaw(6);
    l.setPitch(7);
    p.teleport(l);
    ?
     
  7. setPositionRotation IIRC
     
  8. 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. Problem is, the move() only takes x, y, z
     
  10. 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 Useful x 1
  11. I haven't been messing with NPC's recently, but this could be useful for future reference, thank you <3 :3
     
    • Like Like x 1