Solved Pitch/Yaw

Discussion in 'Plugin Development' started by TheDiamond06, Jun 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    TheDiamond06

    So I am using ProjectileHitEvent to get the location of where an arrow will land. I then teleport the player there. However, the pitch/yaw seems to be opposite whenever a play teleports there and they are looking in the opposite direction for when they shot the arrow. Here is what I tried:

    Code:java
    1.  
    2. private final HashMap<Player, List<Float>>tp = new HashMap<Player, List<Float>>();
    3. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    4. public void noBow(ProjectileLaunchEvent e)
    5. {
    6. if(!(e.getEntity() instanceof Arrow))return;
    7. if(!(e.getEntity().getShooter() instanceof Player))return;
    8. Player p = (Player) e.getEntity().getShooter();
    9. List<Float>facing = new ArrayList<Float>();
    10. facing.add(p.getLocation().getPitch());
    11. facing.add(p.getLocation().getYaw());
    12. tp.put(p, facing);
    13. }
    14.  
    15. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    16. public void bowTP(ProjectileHitEvent e)
    17. {
    18. if(!(e.getEntity() instanceof Arrow))return;
    19. if(!(e.getEntity().getShooter() instanceof Player))return;
    20. Player p = (Player) e.getEntity().getShooter();
    21. if(tp.containsKey(p))
    22. {
    23. p.teleport(e.getEntity().getLocation());
    24. List<Float>facing = tp.get(p);
    25. p.getLocation().setPitch(facing.get(0));
    26. p.getLocation().setPitch(facing.get(1));
    27. tp.remove(p);
    28. }
    29. }
    30.  


    However the pitch and yaw seem to not be settings and doing nothing. What is causing this...
     
  2. Offline

    Lilret123

    @TheDiamond06
    You would have to teleport the player to actually change their pitch/yaw
    You could just get the x, y, and z of the arrow and create a "new" location without setting the pitch and yaw though
     
  3. Offline

    TheDiamond06

    @Lilret123 That then faces the player towards where they shot.
     
  4. Offline

    Lilret123

  5. Offline

    TheDiamond06

    @Lilret123 Example: Say I shot an arrow from block 1 and the arrow lands on block 10. I would teleport to block 10 facing block 1, which is behind the way I was originally facing. How could I make it so the player's pitch/yaw is still looking in the same direction as when they shot. Example: If they are facing south when they shoot the bow they should be facing south when they are teleported.
     
  6. Offline

    blablubbabc

    @TheDiamond06

    I made a few changes to your code: This should let the teleported player keep facing the direction he has before he got teleported.
    Code:
        @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
        public void bowTP(ProjectileHitEvent e)
        {
            if(!(e.getEntity() instanceof Arrow))return;
            if(!(e.getEntity().getShooter() instanceof Player))return;
            Player p = (Player) e.getEntity().getShooter();
            Location pLoc = player.getLocation();
            Location newLoc = e.getEntity().getLocation();
            // keep player's pitch and yaw:
            newLoc.setPitch(pLoc.getPitch());
            newLoc.setYaw(pLoc.getYaw());
            p.teleport(newLoc);
        }
     
  7. Offline

    TheDiamond06

Thread Status:
Not open for further replies.

Share This Page