offsetting player weapon based on angle(SOLVED)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
BruceTheGoose
Citizen
Posts: 76
Joined: Sat Sep 20, 2014 2:54 pm

offsetting player weapon based on angle(SOLVED)

Post by BruceTheGoose »

Hi all!

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


Both the player and weapon models are originally facing 0 degrees

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)
  
Attachments
actual.png
actual.png (2.05 KiB) Viewed 1401 times
desired.png
desired.png (1.53 KiB) Viewed 1401 times
"I don't know."
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests