3 Replies Latest reply on Oct 30, 2011 2:46 PM by kglad

From what I have gathered, _rotation uses radians?

Basically, my initial goal was to make a movieclip rotate towards the mouse. I'm not very good at trigonometry.

Using the help files I found atan2 which seemed to be what I needed. A little fiddling got me to this code:

```var xDist:Number;
var yDist:Number;
var angle:Number;
onMouseMove = function () {
xDist = dot._x-_xmouse;
yDist = dot._y-_ymouse;
angle = Math.atan2(yDist, xDist)*60;
dot._rotation = angle;
};
```

However,

the _rotation is opposite what is expected. This is not a problem as I can just flip the movieclip. But really what im here to ask is, please ecplain this code for me? I don't correctly understand how atan2 works.. and why it needs to be *60.

Basically: How to get a movieclip to rotate towards the mouse.. and why does the code work, I want to learn trigonometry. Thank you.

Math.atan2() returns radians.  the _rotation property uses degrees.

so, you need convert from radians to degrees.  you can do that by multiplying by 180/Math.PI which is approximately 60.  but, you should use the exact conversion, not an approximate conversion:

``````var xDist:Number;
var yDist:Number;
var angle:Number;
onMouseMove = function () {
xDist = dot._x-_xmouse;
yDist = dot._y-_ymouse;
angle = Math.atan2(yDist, xDist)*180/Math.PI;  // atan2, returns the angle with tan = yDist/xDist.
dot._rotation = angle;
};
``````