Head rotation (EntityPlayer) How to set pitch?

Discussion in 'Spigot Plugin Development' started by Dawid, Jul 23, 2018.

Thread Status:
Not open for further replies.
  1. How to set pitch in EntityPlayer?

    I would like to rotate player head to nearly players.
    I create and send yaw location but I don't know how to set and send pitch location :(

    My code:
    Code (Java):
        @EventHandler
        public void onMove(PlayerMoveEvent e)
        {
            Player pl = e.getPlayer();
            for(EntityPlayer ep : Podium.npcs)
            {
                World world = ep.getWorld().getWorld();
             
                Location epLoc = new Location(world, ep.locX, ep.locY, ep.locZ);
             
                double distance = epLoc.distance(pl.getLocation());
             
                if(e.getPlayer().getWorld().equals(world) && distance < 4)
                {
                    epLoc.setDirection(pl.getLocation().subtract(epLoc).toVector());

                    PlayerConnection connection = ((CraftPlayer) pl).getHandle().playerConnection;
                    connection.sendPacket(new PacketPlayOutEntityHeadRotation(ep, (byte) (epLoc.getYaw()*256/360)));
                    //So, how to sendPitch packet?
                }
            }
        }
     
    #1 Dawid, Jul 23, 2018
    Last edited: Jul 24, 2018
  2. I don't think you need to use packets for this, isn't there a "player.setYaw" and "player.setPitch" or something like that? (Might be "player.getLocation().setYaw" and "player.getLocation().setPitch")
     
  3. @KarimAKL I haven't experience working with packets... EntityPlayer haven't method getLocation() and I can't cast it to Player type.
     
  4. Stop using NMS if you don't know how to convert a Bukkit Entity into a NMS Entity and vice-versa.
    However, for NMS entities there is Entity#setPositionRotation which accepts three doubles (for X,Y and Z) and two floats for pitch and yaw.
     
  5. @KarimAKL I know how to get Pitch value but I don't know how to set it for EntityPlayer which I spawned.
    I think I must use some packet to set it.

    @JoJoModding do you want to help me or you want to write some text? Did you look at my first post?
    If you have any idea with send packet which will set pitch for EntityPlayer just write it here ;)
     
  6. PacketPlayOutEntity.PacketPlayOutEntityLook? I mean, what was your problem with looking at http://wiki.vg/Protocol?
    However, if the entity is tracked by the EntityTracker (basically if it's a properly added entity) you have to set it's Entity#pitch field, otherwise the your changes will be overwritten the next time the actual yaw/pitch is broadcasted, which is every few ticks. Therefore you have to (as said) use Entity#setPositionRotation (HINT: Java is Object Oriented and EntityPlayer is a child class of Entity)
     
  7. My bad, didn't understand correctly. Anyway, from this post it seems that the answer is the "PacketPlayOutEntityHeadRotation", hope that works for you.
     
    • Agree Agree x 1
  8. Thanks all for help ;)
    The solution was in PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook packet ;)
     
    #9 Dawid, Jul 24, 2018
    Last edited: Jul 24, 2018
Thread Status:
Not open for further replies.