Something to do with tangent


I have two x and y tilemap positions. (A player and a chest the player wants to find.) I want to get the angle between these two tilemap positions.

All I know is that I need to do something like:

tan(angle) = (chest_x - player_x) / (chest_y - player_y)

I need to find angle. (Degrees preferably, because I want to make a compass)

Does anyone have code or an idea on how to get angle out of the equation I supplied? Or am I completely wrong?

You’re looking for the atan2 function.

Here’s a demo with a duck and some pizza. :slight_smile:

I had a conversation in another thread where I discussed some trig basics: Game Math

As always, if you have any questions, just holler!


Thank you so much! This will be a great help!

1 Like