How to make a bullet face the direction it was fired in...
Posted: Tue Apr 16, 2013 11:30 pm
Hey Guys,
I want to make a Realm of the Mad God-esque RPG (eventually), and I would like the melee attack sprite face the direction it was fired in.
Here is the bit of code which is giving me an issue (I think):
Is it possible to make the angle argument a constant based off the x and y coordinates taken at the mouse click, rather than a variable that tracks the mouse position the whole time?
Thanks in advance guys
I want to make a Realm of the Mad God-esque RPG (eventually), and I would like the melee attack sprite face the direction it was fired in.
Here is the bit of code which is giving me an issue (I think):
Code: Select all
function love.draw()
local x1 = hero.x
local y1 = hero.y
local x2 = love.mouse.getX()
local y2 = love.mouse.getY()
local angle = math.deg(math.atan2(y2 - y1, x2 - x1))
love.graphics.setColor(255, 255, 255)
g.draw(hero.sprite, hero.x, hero.y)
love.graphics.setColor(128, 128, 128)
for i,v in ipairs(slash) do
g.draw(slash.sprite, v["x"], v["y"], angle)
end
end
Thanks in advance guys