Page 1 of 1

Making the player rotate towards the mouse cursor

Posted: Tue Jul 26, 2022 10:32 pm
by danberry
Hi everyone,

I'm very new to using both LOVE and Lua, and so I was wondering how I would go about making the player rotate towards the mouse cursor inside of my game. Any help is appreciated.

Re: Making the player rotate towards the mouse cursor

Posted: Wed Jul 27, 2022 3:20 am
by togFox
Do you have any code that draws your player?

You can copy/paste and we'll see if we can help.

Re: Making the player rotate towards the mouse cursor

Posted: Wed Jul 27, 2022 3:29 am
by ReFreezed
Use math.atan2() to get the angle between two points.

Code: Select all

local angleFromPlayerToMouse = math.atan2(mouseY-playerY, mouseX-playerX)
You could also look at this other recent thread: viewtopic.php?f=4&t=93566

Re: Making the player rotate towards the mouse cursor

Posted: Wed Jul 27, 2022 6:02 am
by danberry
Just got it to work - thank you!