This content has been marked as final. Show 3 replies
I imagine you'd need to continuously keep track of current versus previous _x and _y positions of the object as it is being moved and use some math to figure out what the angle of the path you are following is. You'll probably need to weave in some conditionals to avoid dealing with no movement while still in a drag state and zeroes in a denominator.
Maybe someone else has another idea?
Yup that is pretty much it. NedWebs has described it. I especially like how you thought about the special case when you have no movement. I wouldn't notice that until I was testing it.
Here are a few more tips.
Yes keep the difference in the x and y positions from move to move or frame to frame. Often these are called dx and dy. ("d" for delta meaning change in.)
Use Math.atan2(dy,dx) to get the angle of those changes. The result will be in radians so you need to multiply that by 180 and divide by Math.PI. (Or just multiply by 57.2957795130823).
Math.atan2 takes care of the problems regarding dividing by zero.
You might also want to add some easing so that the angle doesn't just "snap" to the direction but sort of slowly spins around to the direction. I always get it wrong, but I think it would be something like this:
var dA:Number=myClip._rotation - angleMoving;
You can try different values for the damp factor there in the rotation assignment. If it isn't right then switch the order of the subtractions in the dA line....
Great information, guys, thanks a bunch!