Double Jumping Help.
Posted: Thu Aug 27, 2015 9:24 am
So I created an account to ask how to add the ability to double jump, in the process I noticed that I could shorten my code a bit and I accidentally solved the problem. But I'm not here to tell you a success story because I found another problem, if you can time your jumps correctly then you can jump infinitely. So I'm not wondering how to double jump but to restrict it.
One thing worth of note is that the code is from: https://michagamedev.wordpress.com/2014 ... mp-height/ and it was the only code that worked for me (thanks micha). I modified it a bit (off course) to try to add double jumping, and I commented a lot of the code to give you the idea of what I was trying, hopefully this helps.
Thanks in advance. ~bluedude
One thing worth of note is that the code is from: https://michagamedev.wordpress.com/2014 ... mp-height/ and it was the only code that worked for me (thanks micha). I modified it a bit (off course) to try to add double jumping, and I commented a lot of the code to give you the idea of what I was trying, hopefully this helps.
Thanks in advance. ~bluedude
Code: Select all
function mode_jump(mode)
--Sets jump
if mode == 'ground' then
player.mode = 'jump'
player.yvel = -400
end
--Idea is to double jump with this
if mode == 'double jump' then
player.mode = 'dJump'
player.yvel = player.y - 400
end
end
function player.jump(dt)
player.yvel = player.yvel + gravity * dt
-- player.mode is set to ground, when space is pressed it runs mode_jump('ground')
if love.keyboard.isDown(' ') and player.mode == 'ground' then
mode_jump('ground')
end
--the idea of this script is to grant the ability to double jump
--checks if player is in the air
if player.mode == 'jump' and player.yvel > 0 then
player.mode = 'air'
--if player is in the air
if player.mode == 'air' then
--idea is to let them jump again while player.dJump = true
--my idea is to make double jump a power-up
if love.keyboard.isDown(' ') and player.dJump == true then
mode_jump('double jump')
end
end
--resets player.mode so you can jump again
elseif player.mode == 'air' or 'dJump' and player.y == ground_level - player.height and player.yvel >= 0 then
player.mode = 'ground'
end
player.x = player.x + player.xvel * dt
player.y = player.y + player.yvel * dt
end