PDA

View Full Version : [AS2] Aim a pistol to mouse position


CornPoper
12-12-2008, 04:01 PM
I want to make a "game", with a pistol that always aim to where your mouse is, and shoots when you press the mouse button.
I have the pistol, but I don't know how to rotate it to the rigtht position, and I'm only 13 years old so I don't know enough math...
I'd be happy if you can give me a code that can rotate the pistol to the right position, and even happyer if you can explain what does the code actually do so I'll understand.

Thanks =]

Bunney lord
12-14-2008, 03:41 AM
_rotation = Math.atan2((_root._ymouse-this._y), (_root._xmouse-this._x))*180/Math.PI

pradvan
12-15-2008, 02:10 PM
Here is a whole shooting engine with player rotation, along with detailed comments on how everything works.

Shooting Projectile Bullets (http://www.freeactionscript.com/2008/10/game-engine-shooting-projectile-bullets/)

Shameless plug :p