Game Development Reference
AS3.0 has a built-in method called I]pd*]p]j. that will give you the correct angle of rotation between
two objects. One little technical detail you need to deal with, though, is that I]pj*]p]j. returns the
value of the angle in radians , and Movie Clip (and Sprite) objects in AS3.0 don't use radians for their
rotation values; they use degrees. So once you've got the value in radians, you need to apply a very
simple calculation to convert it into degrees. When you have that value, you can rotate the object.
Let me show you just how easy this all is. Figure 9-19 is a grid showing the positions of two objects on
Figure 9-19. Find the angle of rotation between two objects.
Here's how to find out the angle of rotation, from the point of view of the frog:
1. Find the positions of the objects:
2. Subtract the t and u positions of the target object, from the t and u position of the object that
will be doing the rotating:
3. Plug these numbers into the I]pd*]p]j. function. Very importantly, the u value has to come