Advertisement
Evyatar12

TargetLocation.java

Aug 11th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package me.evyatar.target;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.Player;
  5.  
  6. public class TargetLocationCalculator
  7. {
  8.  
  9. public static Location getRelativeLocation(Location from, double xzAngle, double yAngle, double distance)
  10. {
  11. xzAngle = Math.toRadians(xzAngle);
  12. yAngle = Math.toRadians(yAngle);
  13.  
  14. double y = Math.sin(yAngle)*distance;
  15.  
  16. double xzDistance = Math.cos(yAngle)*distance;
  17. double x = Math.cos(xzAngle)*xzDistance,
  18. z = Math.sin(xzAngle)*xzDistance;
  19.  
  20. return from.clone().add(x, y, z);
  21. }
  22.  
  23. public Location getTargetLocation(Player player, double distance)
  24. {
  25. Location playerLoc = player.getLocation();
  26.  
  27. double xzAngle = playerLoc.getPitch() + 90D,
  28. yAngle = playerLoc.getYaw()*-1;
  29.  
  30. return getRelativeLocation(playerLoc, xzAngle, yAngle, distance);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement