Guest User

Untitled

a guest
May 26th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public static Arrow shootWithAngle(Player p, double angle) {
  2.  
  3. Location loc = p.getLocation();
  4.  
  5. Vector direction = p.getEyeLocation().getDirection();
  6.  
  7. Vector dirY = (new Location(loc.getWorld(), 0, 0, 0, loc.getYaw(), 0)).getDirection().normalize();
  8.  
  9. Vector vec;
  10.  
  11. if (angle != 0) {
  12.  
  13. vec = rotateYAxis(dirY, angle);
  14. vec.multiply(Math.sqrt(vec.getX() * vec.getX() + vec.getZ() * vec.getZ())).subtract(dirY);
  15. vec = direction.clone().add(vec).normalize();
  16. }
  17. else {vec = direction.clone();}
  18.  
  19. Arrow a = p.launchProjectile(Arrow.class);
  20.  
  21. a.setVelocity(vec);
  22.  
  23. return a;
  24. }
  25.  
  26. public static Vector rotateYAxis(Vector dir, double angleD) {
  27. double angleR = Math.toRadians(angleD);
  28. double x = dir.getX();
  29. double z = dir.getZ();
  30. double cos = Math.cos(angleR);
  31. double sin = Math.sin(angleR);
  32. return (new Vector(x*cos+z*(-sin), 0.0, x*sin+z*cos)).normalize();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment