Solved PacketPlayInLook

Discussion in 'Spigot Plugin Development' started by TacoLover, May 20, 2016.

  1. Hello,
    I am creating a plugin where I need to rapidly change the player's pitch. I have googled this and found methods that teleport the player with changed pitch/yaw values, but this makes the player "glitch" if they were moving. I was looking at the protocol documentation and found this packet and wondered if I can use this packet using the .a() method in the playerConnection object and force the player's pitch location. I tried to implement this, but there doesn't seem to be any parameters for pitch/yaw, but a quick look at the decompiled packet revealed that the .a() method seems to take a PacketDataSerializer object that contains the pitch/yaw. If anybody knows how to use this packet it would be much appreciated.
    Also if I use this packet, will spigot's location of a player be different because I am not telling the spigot api that I am changing the players pitch/yaw?

    Thanks for any help and hopefully this works!
  2. PacketPlayInLook is the packet sent by the client and received by the server. It makes no sense to change this packet, the only result would be that the server would think the player is at a different location and the client would get out of sync.

    Unfortunately, the only way to do this is to teleport the player, so that both the server and the client know the new location of the player. Also, I think what you mean with "glitch" is the velocity of the player being set to 0,0,0 when teleported. Try to set the velocity of the player after teleporting to what it was before teleporting. Haven't ever tried this before, but sounds like it might work. Worth a try I think!
  3. Okay thanks for the response!
    I won't be using PacketPlayInLook anymore because of the out of sync stuff:p
    Also tried setting player velocity right after teleport to their previous velocity before teleport, and that seemed to do an okay job of preventing the "glitch", so I might be using that, but I am calling it every tick :(
    Is there any other way to approach this without using teleport/setVelocity?

    • Like Like x 1
  4. I think there is not. You are looking for a way to safely change the pitch of the client. The only pitch related packet that the client has is the teleport packet.
  5. Maybe in the PlayerMoveEvent. Possibly get the To() and set the direction.
  6. Won't have any effect, it's a read-only field. Unless you teleport the player to event.getTo() after that, but that has the same result as teleporting normally.

    Nevermind, isn't read only, but if changed to something different, the server sends the teleport packet as well.
    • Agree Agree x 1
  7. Ah alright, thanks for clearing that up!
    • Friendly Friendly x 1
  8. Alright I mark this one solved-ish.

    Thanks for the help!
    • Friendly Friendly x 1