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?
Need help with rotating on my top down shooter project
-
- Prole
- Posts: 37
- Joined: Fri Aug 02, 2013 1:44 pm
Need help with rotating on my top down shooter project
Sharing the one world
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Re: Need help with rotating on my top down shooter project
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:
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.
Code: Select all
angle = -math.atan2 ( mouse.y - player.y, mouse.x - player.x )
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.
-
- Prole
- Posts: 37
- Joined: Fri Aug 02, 2013 1:44 pm
Re: Need help with rotating on my top down shooter project
I dont quite understand, can you show a demonstration in love?
Sharing the one world
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Re: Need help with rotating on my top down shooter project
Kinda like this. Note the mousepressed function.
- Attachments
-
datafile.love
- (1.01 KiB) Downloaded 160 times
-
- Prole
- Posts: 37
- Joined: Fri Aug 02, 2013 1:44 pm
Re: Need help with rotating on my top down shooter project
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
http://www.mediafire.com/download/kbc6d ... le(2).love
Sharing the one world
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Also check out my friend's game!
http://love2d.org/forums/viewtopic.php?f=5&t=43276
Re: Need help with rotating on my top down shooter project
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest