If you have no idea what the title of this blog post is referring to, check out this page which explains the idea. It's some pretty simple triginometry.
For those of you who've ever tried (like me) to do this in flash (or I imagine any programming language), you probably will have run into problems using code like this:
rotation = Math.atan(y / x) / Math.PI * 180;
This line is basically just converting a unit vector into an angle which is used to rotate a sprite. Simple enough right? Well check out the output:
Two of the arrows are fine, the other two are pointing the wrong way.
The solution is to change the code to use atan2 as follows (passing in the y & x, without doing any division):
rotation = Math.atan2(y, x) / Math.PI * 180;
Which fixes the output as below:
This also means you don't have to worry about divide by zero errors.
This may seem pretty obscure, but one day you'll be doing this and you'll remember this post and thank me ;)