How can i make a Player that Jump Up and Falls Down
Posted: Tue Apr 10, 2012 5:55 pm
How can i make a Player that Jumps Up and Falls Down? I Haven't Any Idea :/ the Key for Jumping must be Space :s
Code: Select all
player = {
x = 0,
y = 0,
yVel = 0
}
Code: Select all
function love.update(dt)
player.yVel = player.yVel + gravity * dt
player.y = player.y + player.yVel * dt
end
Code: Select all
function love.update(dt)
if not onGround() then --if the onGround function returns false
player.yVel = player.yVel + gravity * dt
player.y = player.y + player.yVel * dt
end
end
Code: Select all
function love.update(dt)
if not onGround() then --if the onGround function returns false
player.yVel = player.yVel + gravity * dt
player.y = player.y + player.yVel * dt
else
player.yVel = 0
end
end
Code: Select all
function love.keypressed(key)
if key == " " then --Checks if the space key was pressed
player.yVel = -500
end
end
Then i'd suggest trying something simpler first Check out some of the tutorials on the wiki.Pigzo wrote:Umm I Didn't Understand Anything :/
You need to define the variable gravity.counterman2026 wrote:help!, it says that there is an error to perform on global 'gravity'(a nil value)
Code: Select all
function love.load()
gravity = [[Whatever works for your game]]
end