0
\$\begingroup\$

This question already has an answer here:

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?

\$\endgroup\$

marked as duplicate by MichaelHouse Feb 21 '14 at 15:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ 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 :) \$\endgroup\$ – Terje Feb 21 '14 at 13:02
  • \$\begingroup\$ 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. \$\endgroup\$ – user42504 Feb 21 '14 at 15:04
  • \$\begingroup\$ 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. \$\endgroup\$ – user42504 Feb 21 '14 at 16:15