Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Arrow shootWithAngle(Player p, double angle) {
- Location loc = p.getLocation();
- Vector direction = p.getEyeLocation().getDirection();
- Vector dirY = (new Location(loc.getWorld(), 0, 0, 0, loc.getYaw(), 0)).getDirection().normalize();
- Vector vec;
- if (angle != 0) {
- vec = rotateYAxis(dirY, angle);
- vec.multiply(Math.sqrt(vec.getX() * vec.getX() + vec.getZ() * vec.getZ())).subtract(dirY);
- vec = direction.clone().add(vec).normalize();
- }
- else {vec = direction.clone();}
- Arrow a = p.launchProjectile(Arrow.class);
- a.setVelocity(vec);
- return a;
- }
- public static Vector rotateYAxis(Vector dir, double angleD) {
- double angleR = Math.toRadians(angleD);
- double x = dir.getX();
- double z = dir.getZ();
- double cos = Math.cos(angleR);
- double sin = Math.sin(angleR);
- return (new Vector(x*cos+z*(-sin), 0.0, x*sin+z*cos)).normalize();
- }
Advertisement
Add Comment
Please, Sign In to add comment