public void lookAtPoint(final Location point) { if (this.getEntity().getBukkitEntity().getWorld() != point.getWorld()) return; final Location npcLoc = ((LivingEntity) this.getEntity().getBukkitEntity()).getEyeLocation(); final double xDiff = point.getX() - npcLoc.getX(); final double yDiff = point.getY() - npcLoc.getY(); final double zDiff = point.getZ() - npcLoc.getZ(); final double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); final double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff); double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI; final double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90; if (zDiff < 0.0) newYaw = newYaw + Math.abs(180 - newYaw) * 2; this.setYaw((float) (newYaw - 90)); this.setPitch((float) newPitch); }
public double getDistance2(Player player1, Player player2) { Location loc1 = player1.getLocation(); Location loc2 = player1.getLocation(); return Math.sqrt( Math.pow(loc1.getX() - loc2.getX(), 2.0D) + Math.pow(loc1.getY() - loc2.getY(), 2.0D) + Math.pow(loc1.getZ() - loc2.getZ(), 2.0D)); }