A Flash Developer Resource Site

# Thread: Calculate the angle between 2 movie clips

1. ## Calculate the angle between 2 movie clips

Hi guys!
How can I calculate the angle made by 2 movie clips. Each one representing a line.
Thanks,

2. use this:
Code:
```// pass references to your movieclips using vectorInputN
// NOTE: the angle returned depends on relationship of vectorInputs!

function solveAngle(	vectorInput1:Object,
vectorInput2:Object,
convertToDegrees:Boolean):Number {

var nOutput:Number = null;

var opp:Number = -(vectorInput2._y - vectorInput1._y);
var adj:Number =   vectorInput2._x - vectorInput1._x;

nOutput = 	(convertToDegrees) ?
Math.atan2(opp, adj) * (180 / Math.PI) :

return nOutput;
}```
+Q__

3. nice code

4. Thanks Q__Hybrid ! I'm really grateful!

5. angle = Math.Atan2(movieClip1._y - movieClip2._y, movieClip1._x - movieClip2._x)*180/Math.PI

6. the angle returned depends on relationship of vectorInputs

7. For future refernce : "atan2" not Atan2

angle = Math.atan2(movieClip1._y - movieClip2._y, movieClip1._x - movieClip2._x)*180/Math.PI

Lame first post.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap