# Java Angle Math: Calculate how near the player looks to an entity [duplicate]

I am programming a Minecraft Bukkit plugin and need a way to calculate an input number from 0 to 360 for displaying a custom compass / radar. So if the player directly looks at the object (shouldn't handle viewing height or position height), this number would be 0 and if the player's back is looking on the object it would be 180.

I already successfully calculated both numbers I guess I need:

1. The absolute looking angle of the player. Is 0 when the player looks in north direction and 180 in south direction.

2. The location angle between the player's position and the object's position. Using Math.atan2 to get the angle between [X, Z] of these locations.

Both values seem to be calculated correctly. But I can't find out what to do to get the number I described at first. Tried substraction, addition. Any ideas?

• Are you looking to convert the result your atan2 to (0-360) ? If so, you can do it with Math.toDegrees(). If not, I am not sure I understand your problem :) – Terje Feb 21 '14 at 13:02
• Yeah, already doing this. The second input number I am describing is the location angle between two points, not the looking angle I'm trying to get as described in first paragraph. – user42504 Feb 21 '14 at 15:04
• I guess my description is too unclear. I know how to calculate the angle between to points. But one of those points has a rotation. I have to check if this point is looking at the other point. – user42504 Feb 21 '14 at 16:15