Using mouse to aim

4 posts

Flag Post

Say you were making Tanks 2007, how do you find the right _rotation so that the turret of the tank lines up with your mouse pointer?

 
Flag Post

Use this code on the turret.

onClipEvent (enterFrame) {
dx = root._xmouse-this.x;
dy = root._ymouse-this.y;
ang = Math.atan2(dy, dx);
with (this) {
_rotation = ang/Math.PI*180;
}
}

 
Flag Post

( BTW just a tip: I recommend staying away from onClipEvents )

 
Flag Post

Nice, thank you

:)