Set look position for entity to players

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

  1. Hi, how to set position for entity to look at players near 5 distance?
    My current code:
    Code (Java):
     @EventHandler
        public void onMove(PlayerMoveEvent e)
        {
            Player pl = e.getPlayer();
            for(EntityPlayer ep : Podium.npcs)
            {
                Location epLoc = new Location(ep.getWorld().getWorld(), ep.locX, ep.locY, ep.locZ);
               
                double distance = epLoc.distance(pl.getLocation());
               
                if(distance < 6)
                {
                    System.out.println("SEND PACK");
                    ep.setPositionRotation(ep.locX, ep.locY, ep.locZ,pl.getLocation().getYaw(), pl.getLocation().getPitch());
                    PlayerConnection connection = ((CraftPlayer) pl).getHandle().playerConnection;
                    connection.sendPacket(new PacketPlayOutEntityHeadRotation(ep, (byte) (ep.yaw* 256 / 360))); //* 256 / 360
                }
               
            }
        }