-
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 ?
-
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.
-