1.16.x Camera Packet (Spectator Target) for Arrows

Discussion in 'Spigot Plugin Development' started by AigleZ, Oct 10, 2020.

  1. Hi,
    I'm creating this post, because i'm facing a "weird" situation with setting a player's spectator target,
    when i set it, i listen to the EntityBowShootEvent, and set the shooter's spectator target to that projectile (in my situation it's an arrow) but sometimes the camera is backward, like i shoot the arrow 10 blocks forward when i set the spectator target i see block behind me, and sometime the camera is sideway, when i did some tests i figured out (it may be false) that it depends on where you shot the arrow:

    It works if you're facing Negative Z or Positive Z, and it doesn't work (it does it backward) if you are facing Negative X or Positive X (as i said above it might be wrong)

    My code is basically Player#setGameMode to spectator then Player#setSpectatorTarget

    Thanks.
     
  2. I guess that happens because the player's camera is set to 0 yaw and pitch
     
  3. So it can be fixed or not ?
     
  4. You could try something like this:
    Code (Java):

            Player player = ...;
            Arrow arrow = ....;
            player.setGameMode(GameMode.SPECTATOR);
            player.setSpectatorTarget(arrow);
            Location loc = player.getLocation();
            Location arrowLoc = arrow.getLocation();
            loc.setYaw(arrowLoc .getYaw());
            loc.setPitch(arrowLoc .getPitch());
            player.teleport(loc);
     
    I haven't tried it, so it may don't work
     
  5. I tried the code above and it's not working, when i face Negative/Positive X i see the things backward
     
  6. Paper 1.16.2 (build: 208)
     
  7. I tried this using 1.8.8, the player camera doesn't follow the arrow, but it always in the right direction
     
  8. it doesn't follow the arrow so it doesn't work ?