# Atan2 - stop lookat flipping over 180 degrees

**URL:** <https://forum.logik.tv/t/atan2-stop-lookat-flipping-over-180-degrees/9882>\
**Category:** Tips and Tricks\
**Tags:** expressions\
**Created:** [January 24, 2024, 4:31pm UTC](https://forum.logik.tv/t/atan2-stop-lookat-flipping-over-180-degrees/9882 "2024-01-24T16:31:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leovfx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/leovfx/32/12472_2.png) [@leovfx](https://forum.logik.tv/u/leovfx)\
**Post date:** [January 24, 2024, 4:31pm UTC](https://forum.logik.tv/t/atan2-stop-lookat-flipping-over-180-degrees/9882/1 "2024-01-24T16:31:38Z")

</div>

I just solved something that’s annoyed me for a while…

When you’ve 2d tracked 2 objects in a scene and want a lookat between them,

But if you use a lookat (either expression or link) between 2 axis both with z position 0, the axis with the lookat will flip round 180 degrees when x or y values on either axis cross through 0.

Here’s the solution (instead of using lookat, enter this expression into rotation.z)…  
degrees(atan2(axisA.position.y-axisB.position.y,axisA.position.x-axisB.position.x))

Here’s why it works…

> **[atan2](https://en.wikipedia.org/wiki/Atan2)**
>
> In computing and mathematics, the function atan2 is the 2-argument arctangent. By definition, 
>   
>     
>       
> θ
> =
> atan2
> ⁡
> (
> y
> ,
> x
> )
>       
>     
> {\\displaystyle \\theta =\\operatorname {atan2} (y,x)}
>   
> is the angle measure (in radians, with 
>   
>     
>       
> −
> π
> \<
> θ
> ≤
> π
>       
>     
> {\\displaystyle -\\pi \<\\theta \\leq \\pi }
>   
> ) between the positive 
>   
>     
>       
> x
> ...

I never knew about atan2 until today. I’ve always just used atan and been annoyed.

---

<div class="post-metadata">

**Author:** ![Sinan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/sinan/32/155_2.png) [@Sinan](https://forum.logik.tv/u/Sinan)\
**Post date:** [January 24, 2024, 7:47pm UTC](https://forum.logik.tv/t/atan2-stop-lookat-flipping-over-180-degrees/9882/2 "2024-01-24T19:47:08Z")

</div>

Nice one. I learned about it when setting up the IK rig in Flame.

---

<div class="post-metadata">

**Author:** ![leovfx](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/leovfx/32/12472_2.png) [@leovfx](https://forum.logik.tv/u/leovfx)\
**Post date:** [January 25, 2024, 6:28am UTC](https://forum.logik.tv/t/atan2-stop-lookat-flipping-over-180-degrees/9882/3 "2024-01-25T06:28:57Z")

</div>

Ah yes. I imagine that would need to be covered in expressions like this. Might take a look.
