Im having troubles with rotating a gun towards the mouse, any help?

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
Cyzmix
Prole
Posts: 3
Joined: Tue Aug 30, 2022 8:20 pm

Im having troubles with rotating a gun towards the mouse, any help?

Post by Cyzmix »

Ive been trying for 3 days now and cant get it fixed any help ?
Thx
Attachments
prototype.love
Love file (the game)
(4.14 MiB) Downloaded 79 times
anyonehelppls.lua
Its gun.lua btw i just renamed it
(501 Bytes) Downloaded 79 times
User avatar
BrotSagtMist
Party member
Posts: 636
Joined: Fri Aug 06, 2021 10:30 pm

Re: Im having troubles with rotating a gun towards the mouse, any help?

Post by BrotSagtMist »

Code: Select all

love.graphics.draw(gunsprite, px, py, -math.atan2(635- love.mouse.getX(),360- love.mouse.getY() ) +math.pi/2	, 1.3, 1.3, gunsprite:getWidth(), gunsprite:getHeight()/2)
bascally you account for translation when in fact you wanted it static.
This huge translation will bite you in the ass later on, i do not recommend it.
obey
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Im having troubles with rotating a gun towards the mouse, any help?

Post by ReFreezed »

You need to convert the mouse position from screen coordinates to world coordinates before you can calculate the difference to the player for use in atan2(). It looks like the camera library you're using has a relevant function: camera:mousePosition().
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Cyzmix
Prole
Posts: 3
Joined: Tue Aug 30, 2022 8:20 pm

Re: Im having troubles with rotating a gun towards the mouse, any help?

Post by Cyzmix »

Ty all so much for the help !
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 7 guests