[Help needed] Math.atan2()
Posted: Mon Jul 29, 2013 11:29 pm
Hi! This is my first post in this forum, so, yeah happy to be with you. So, MY problem is this:
I want to do a top down shooter, but I don't really know how. I already searched this and I found 2 topics. One redirected me to math.atan and math.atan2 and the other one had even an example. BUT, sadly, and becouse of how I am and how I think, I can't get it to work. It actually works but it's really weird. This is the code:
The pj.png is a 16x16 square by the way. As said, works but it's really weird. Help would be appreciated.
Thanks for reading,
Raxe88
I want to do a top down shooter, but I don't really know how. I already searched this and I found 2 topics. One redirected me to math.atan and math.atan2 and the other one had even an example. BUT, sadly, and becouse of how I am and how I think, I can't get it to work. It actually works but it's really weird. This is the code:
Code: Select all
local function main()
function love.load()
--// Load sprites and tiles
player = love.graphics.newImage("/images/pj.png")
--//Declaring variables
--player = {}
playerx = love.graphics.getWidth()/2
playery = love.graphics.getHeight()/2
end
function love.update(dt)
mousex, mousey = love.mouse.getPosition()
pointRadians = math.atan2((mousey - playery), (mousex - playery))
--pointRadians = math.angle(playerx,playery,mousex,mousey)
end
function love.draw()
--love.graphics.setColor( 0, 0, 0, 255 )
love.graphics.print("This is a fail",0,0)
love.graphics.draw(player, playerx, playery, pointRadians)
love.graphics.setColor(255,255,255,255)
love.graphics.line(playerx+8,playery+8,mousex,mousey)
end
end
main()
Thanks for reading,
Raxe88