In my game, the square shaped player must jump through tight holes in incoming pillars. to ensure that it looks visually correct I have defined the jump height with the following line:
Code: Select all
JUMP_VEL = math.sqrt(GRAVITY*JUMP_HEIGHT/0.5)
My update function looks something like this:
Code: Select all
if player.inair then
player.yv = poly.yv+GRAVITY*dt
if player.y+player.yv*dt > GROUND then
player.inair = false
player.y = GROUND
player.yv = 0
end
end
player.y = player.y+player.yv*dt
This function executes when space is pressed:
Code: Select all
function eventJump()
if poly.inair then return end
poly.yv = -JUMP_VEL
poly.inair = true
end
The problem is that when observing this in action, the player fails to reach the desired height, and not only that, it also jumps a slightly different height each time. I've tried correcting the height once it reaches its peak height, but it looks jerky and ew. I have no clue what's going on, and it's important to me that everything looks smooth and perfect. So if someone could tell me what's up that would be great, thanks in advance.