

They're supposed to go together and the arms should point towards the mouse pointer. I'm not sure how to; 1. Move both the arms and body as one entity; 2. Pivot the arms so they look like they're attached.
Anyone have any idea how to do so?
That's not that hard1. Move both the arms and body as one entity
Code: Select all
self.body = {image = love.graphics.newImage("body.png"), x = self.x, y = self.y, ox = 0, oy = 0}
self.arms = {image = love.graphics.newImage("arms.png"), x = self.x, y = self.y, ox = 3, oy = 25}
Code: Select all
function Player:updateBody(dt)
-- Body --
self.body.x = self.x + self.body.ox
self.body.y = self.y + self.body.oy
-- Arms --
self.arms.x = self.x + self.arms.ox
self.arms.y = self.y + self.arms.oy
end
Here you can use math.atan2. This can be added to the updateBody function :2. Pivot the arms so they look like they're attached
Code: Select all
local mx, my = love.mouse.getPosition()
self.arms.rotation = math.atan2(self.arms.y - my, self.arms.x - mx)
Code: Select all
love.graphics.draw(self.body.image, self.body.x, self.body.y)
love.graphics.draw(self.arms.image, self.arms.x, self.arms.y, self.arms.rotation, -1, -1, 0, self.arms.height/2)
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests