Jumping Problem
Posted: Thu Oct 09, 2008 11:23 pm
Okay, so I'm trying to (very simply) make a little dude jump up and land. So far it's actually going okay. I got him to jump. But he jumps at OMG ridiculous speed versus the left and right which are far more reasonable. I know dt has to figure into this SOMEWHERE but it's escaping me where (I don't understand a lot of the math behind what I'm doing).
So here's what I have so far:
Any ideas?
So here's what I have so far:
Code: Select all
-- Make a dude jump up and land. Also allow the movement left and right.
function load()
dude = love.graphics.newImage("dude.png")
x = 300
y = 400
speed = 100
jump = 0
end
function update(dt)
if love.keyboard.isDown(love.key_right) then
x = x + (speed * dt)
elseif love.keyboard.isDown(love.key_left) then
x = x - (speed * dt)
end
if love.keyboard.isDown(love.key_up) then
if jump == 0 then
jump = 1
accel = 10
velocity = 100
end
end
if jump == 1 then
velocity = (velocity - accel)
y = y - velocity
if y >= 400 then
jump = 0
velocity = 0
accel = 0
end
end
end
function draw()
love.graphics.draw(dude,x,y)
end