A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3 & rotation issue

  1. #1
    Senior Member SlimSlaby's Avatar
    Join Date
    May 2005
    Posts
    158

    AS3 & rotation issue

    I have a character that I am having follow a circle using Math.cos and Math.sin


    I also want to rotate the character so his facing is correct each frame. I am saving the last x,y location and getting the angle between it and the new location to determine the facing

    I am using this code :

    _facing = Math.atan2(last_y-loc_y,last_x -loc_x)
    rotation =( _facing / Math.PI * 180) - 180


    note -- the -180 is for offsetting the default angle of the movieclip.
    Which actually works.... EXCEPT for some reason every once in awhile that calculation completely flips my rotation for one frame?!!?

    Make sense to anyone ?
    Last edited by SlimSlaby; 01-21-2008 at 01:59 PM.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Yeah, your character is going around for 360 degrees just fine but when it loops he jumps from 360 to 0...so the calculation between the last and the next position gets crazy. Do some traces to find the exact point where this happens and then write in an if-then to correct for it.

  3. #3
    Senior Member SlimSlaby's Avatar
    Join Date
    May 2005
    Posts
    158
    Thanks, that fixed it.

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