Atan2 - stop lookat flipping over 180 degrees

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)…

Here’s why it works…

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


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

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