Page 1 of 1
Need help with rotating on my top down shooter project
Posted: Sat Aug 03, 2013 2:49 am
by AtomCastDev
I have been working on a top down zombie shooter for quite a while.It has a few features into it like a cool futuristic yet post apocalyptic environment, cool gun sprites and a mouse aiming system.
But what has gotten me stumped for the last 2 days is a code to make the character rotate into the direction my mouse is, if that is too complicated (I am a newbie at love2-D mouse code) then if possible can it just be so that the mouse will aim somewhere and shoot using the lmb,when the lmb is pressed it will also make the character will rotate to the direction the mouse button was pressed.
can anyone help a stumped newbie like me?
Re: Need help with rotating on my top down shooter project
Posted: Sat Aug 03, 2013 4:54 am
by raidho36
You would need to use some trigonometry, but it's quite easy. All you need is math.atan2 ( y, x ). It would compute a radian angle between coordinates origin and X-Y point. To compute an angle between two points, for each axis you subtract coordinates from target point to origin point:
Code: Select all
angle = -math.atan2 ( mouse.y - player.y, mouse.x - player.x )
Note that this function has first argument Y and second X, and since LÖVE have inverted Y-axis and therefore angles go clockwise rather than counter-clockwise, you would need negative of the returned angle.
I assume you've already managed to get it shooting with the mouse button, so all it takes now is to use the function described.
Re: Need help with rotating on my top down shooter project
Posted: Sun Aug 04, 2013 7:34 pm
by AtomCastDev
I dont quite understand, can you show a demonstration in love?
Re: Need help with rotating on my top down shooter project
Posted: Sun Aug 04, 2013 8:39 pm
by raidho36
Kinda like this. Note the mousepressed function.
Re: Need help with rotating on my top down shooter project
Posted: Tue Aug 06, 2013 7:03 pm
by AtomCastDev
Do you think it is possible to apply your code into my project without changing anything?
http://www.mediafire.com/download/kbc6d ... le(2).love
Re: Need help with rotating on my top down shooter project
Posted: Tue Aug 06, 2013 8:38 pm
by raidho36
It's a one-liner function, of course it's possible.
Also, posting multimegabyte project full of unrelated to the problem stuff and with probably complex structure with no explanations given and expecting people to do everything for you isn't exactly following online etiquette of asking for help IMO.