Using mouse to aim

Subscribe to Using mouse to aim 4 posts

avatar for Slackore Slackore 2 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?

 
avatar for Kannushi_Link Kannushi_Link 523 posts
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;
}
}

 
avatar for arcaneCoder arcaneCoder 2354 posts
Flag Post

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

 
avatar for Slackore Slackore 2 posts
Flag Post

Nice, thank you

:)