A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Rotation and deceleration?

  1. #1
    Junior Member
    Join Date
    Oct 2001

    Rotation and deceleration?

    I have a clip which orients itself to the mouse using Math.atan2(). The rotation calculation of the clip includes some deceleration to smooth the effect. The calculation goes crazy when:

    _root._xmouse < clip._x && _root._ymouse > clip._y

    I can identify in the code when it happens, but need some help to stop it... anyone?

    See the file attached for an example.
    Attached Files Attached Files

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Los Angeles
    Below this line:


    Add the following 2 lines:

    while (d < _rotation-180) d += 360;
    while (d > _rotation+180) d -= 360;

    Your problem was caused by the fact that atan2 returns a value from -PI to PI (which you were converting to -90 to 270).

    The point where the mouse went crazy was the point where it switched from positive to negative.

    I changed it to find the nearest equivalent rotation point on the circle (for any given angle, the angle you want to tween to shouldn't be there 180 degrees away). Adding or subtracting 360 doesn't change the desired angle, but reduces the amount of tweening that _rotation needs to find it.

  3. #3
    Junior Member
    Join Date
    Oct 2001
    Thanks, jbum - perfect! And thanks for the explanation, I know it's only elemental trig but I haven't touched it since high school and I have to learn it all over again.

  4. #4
    Junior Member
    Join Date
    Nov 2008
    Thanks a lot. It is work perfect!

Posting Permissions

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

Click Here to Expand Forum to Full Width

HTML5 Development Center