So I'm trying to make a circular pong game and I'm making the paddle at the moment
In my main.lua, I have this code inside love.update:
pad:update(
function(dt,self)
local mouseX,mouseY=love.mouse.getPosition()
self.rot=math.atan2((mouseY - self.y), (mouseX - self.x))
self.x = circleRadius*math.cos(self.r) + self.orgX;
self.y = circleRadius*math.sin(self.r) + self.orgY;
self.r=self.r+.5*dt
end,
dt
)
(Paddle.lua, the paddle file, executes the function given by the caller continuously in the update function)
It does point towards the mouse, but not in the way I want it to. Currently, it's like this (badly illustrated since snipping tool doesn't capture the mouse so I have to draw where it would be)
Instead, I want it like this
The anchor point of the paddle is in the middle as in it's offset on the x and y axis by half the width and height, respectively. (it's a image file, since you can't really rotated love.graphics.rectangle objects)
Anyone know how to fix this?
To rotate additional 90°, replace
self.rot=math.atan2((mouseY - self.y), (mouseX - self.x))
with
self.rot=math.atan2((mouseX - self.x), -(mouseY - self.y))