# Something to do with tangent

**URL:** <https://forum.makecode.com/t/something-to-do-with-tangent/3914>\
**Category:** Help\
**Created:** [October 16, 2020, 1:02pm UTC](https://forum.makecode.com/t/something-to-do-with-tangent/3914 "2020-10-16T13:02:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 16, 2020, 1:02pm UTC](https://forum.makecode.com/t/something-to-do-with-tangent/3914/1 "2020-10-16T13:02:26Z")

</div>

Hello!

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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)\
**Post date:** [October 16, 2020, 3:22pm UTC](https://forum.makecode.com/t/something-to-do-with-tangent/3914/2 "2020-10-16T15:22:51Z")

</div>

You’re looking for the `atan2` function.

> **[Math.atan2()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)**
>
> The Math.atan2() function returns the angle in the plane (in radians) between the positive x-axis and the ray from (0,0) to the point (x,y), for Math.atan2(y,x).

Here’s a demo with a duck and some pizza. 🙂

> **[Trig Demo](https://arcade.makecode.com/68113-67145-98748-20357)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I had a conversation in another thread where I discussed some trig basics: [Game Math](https://forum.makecode.com/t/game-math/2934)

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

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [October 16, 2020, 4:37pm UTC](https://forum.makecode.com/t/something-to-do-with-tangent/3914/3 "2020-10-16T16:37:30Z")

</div>

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