Making the player rotate towards the mouse cursor

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
danberry
Prole
Posts: 2
Joined: Tue Jul 26, 2022 6:22 pm

Making the player rotate towards the mouse cursor

Post 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.
coolors
User avatar
togFox
Party member
Posts: 828
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Making the player rotate towards the mouse cursor

Post by togFox »

Do you have any code that draws your player?

You can copy/paste and we'll see if we can help.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Making the player rotate towards the mouse cursor

Post 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
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
danberry
Prole
Posts: 2
Joined: Tue Jul 26, 2022 6:22 pm

Re: Making the player rotate towards the mouse cursor

Post by danberry »

Just got it to work - thank you!
coolors
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests