all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

Rotate Error


Rotate Error Elad83
10/19/2005 10:42:42 PM
flash actionscript:
I'm writing a simple shooting game of a man that point a gun and shoot on birds.
the gun barrel is pointing in the cursor direction, and when ever i move the
cursor, the gun's barrel should point to the new postion.
how can i do it?
i tried to calculate the degrees difference between the old mouse postion and
the new one, and to rotate the gun in that degree, but it didn't work.
i used the formula:
_root.gun_mc._rotation = Math.atan2(oldYPos,oldXPos)*180/Math.PI -

Math.atan2(_root.cursor_mc._y,_root.cursor_mc._x)*180/Math.PI;

please help me if you can.
thanks :)
Re: Rotate Error PTrice
10/19/2005 10:55:48 PM
lets say the base of the gun is at the top left for simplicity (0,0)

Orient the gun pointing directly right (0 degrees).

Now lets say the mouse cursor is at 500,100
Divide them Y/X 100/500 = .2
the atan of .2 is 11.3
so rotate your gun 11.3 degrees.

Dont worry about the old mouse position. The only thing that matters is
CURRENT mouse position relative to gun position.
AddThis Social Bookmark Button