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

    Gradient to _rotation - please explain trigonometry?

    prodigalmaster Level 2

      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;



      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.