So I want to get the degrees between 2 points, But when I want it to return 180, it returns 0... 0, 90 and 270 does work, but when its 180 it returns 0.. This is my code:
Location loc1 = new Location(Bukkit.getWorld("world"), 1, 0, 0);
Location loc2 = new Location(Bukkit.getWorld("world"), -1, 0, 0);
float pitch = Utils.yawpitch(loc1, loc2).getPitch();
public static Location yawpitch(Location loc, Location toloc) {
loc = loc.clone();
double x = toloc.getX() - loc.getX();
double y = toloc.getY() - loc.getY();
double z = toloc.getZ() - loc.getZ();
double dxz = Math.sqrt(Math.pow(x, 2) + Math.pow(z, 2));
loc.setPitch((float) -Math.atan(y / dxz));
loc.setPitch(loc.getPitch() * 180f / (float) Math.PI);
return loc;
}
So I have my first point on the left and my second point on the right, so it should be 180, but this will return "0".