Page 1 of 1

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

Posted: Tue Aug 30, 2022 8:27 pm
by Cyzmix
Ive been trying for 3 days now and cant get it fixed any help ?
Thx

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

Posted: Tue Aug 30, 2022 9:16 pm
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.

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

Posted: Tue Aug 30, 2022 11:38 pm
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().

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

Posted: Wed Aug 31, 2022 11:20 am
by Cyzmix
Ty all so much for the help !