Player diagonal speed
Posted: Mon Jul 23, 2018 7:54 pm
Hello friends, how do I get my player to move diagonally?
Player movement code:
And the variables setup:
Player movement code:
Code: Select all
function playerMovement() -- Contains the player movement logic
if love.keyboard.isDown("w") then
Player.y = Player.y - Player.speed * deltaT
end
if love.keyboard.isDown("a") then
Player.x = Player.x - Player.speed * deltaT
end
if love.keyboard.isDown("s") then
Player.y = Player.y + Player.speed * deltaT
end
if love.keyboard.isDown("d") then
Player.x = Player.x + Player.speed * deltaT
end
end
Code: Select all
function playerSetup() -- Contains the player and his fields
Player = {} -- Create a table to store the player fields
Player.texture = love.graphics.newImage("assets/player.png") -- Import the texture of player and places it in a variable
Player.x = love.graphics.getWidth()/2-- Player X location is equal to the width of the windows divided by 2
Player.y = love.graphics.getHeight()/2 -- The same from above, but is the Player Y location
Player.size = 0.45 -- Player size (Scale factor)
Player.speed = 250 -- Player speed
Player.r = 0 -- Player radians
end