I'm trying to rotate and offset the player's weapon based on the angle of the player. Not really sure how to go about this maybe you guys could help.
Code: Select all
-- Reduced code
player = {}
player.x = 0
player.y = 0
player.angle = 0
player.weapon = {}
player.weapon.x = player.x
player.weapon.y = player.y
player.weapon.model =model2
function player.update(dt)
player.angle = math.atan2(love.mouse.getY()-player.y,love.mouse.getX()-player.x)
end
function player.draw()
love.graphics.draw(model2,player.weapon.x,player.weapon.y,player.angle,2,1,12.5,2.5)
love.graphics.draw(model,player.x,player.y,player.angle,1,1,25,25)
end
EDIT:
Solved it with this:
Code: Select all
local rot = player.angle + math.atan2(20,35)
player.weapon.x = player.x + math.sqrt((35)^2+(20)^2) * math.cos(rot)
player.weapon.y = player.y + math.sqrt((35)^2+(20)^2) * math.sin(rot)