Double Jump

Hi, I am a new at this so I’ve been following a tutorial that teaches you how to create an endless rounner game. 

function touched( event )
 if hero.isAlive then
  if(event.phase == “began”) then
   if(onGround) then
    hero.accel = hero.accel + 25
   end
  end
 else
  if(event.x < gameOver.x + 150 and event.x > gameOver.x - 150 and event.y < gameOver.y + 95 and event.y > gameOver.y - 95) then
   restartGame()
  end
end

From what I found out, this is the function that allows you to jump, however I would like to make it so it double jumps, which is not explained in the tutorial. 

Could someone help me out?

Thanks in advance. 
 

You’re proving little code so it’s hard to tell for sure, but it looks like you code says something like

“if the hero is standing on ground then add 25 to his acceleration”.

Presumably when the hero lands “onGround” is set to false or nil.

What you could is create a variable called jumpCounter (with default value zero) and use that instead of the “onGround” variable.

In the “touched” function you could then say something like:

" If jumpCounter is smaller then 2 then: add 1 to the jumpCounter and set hero.accel to hero.accel + 25".

And when then hero lands, you can set the jumpCounter to zero again.

p.s. In code that would read something like this:

if jumpCounter < 2 then

    jumpCounter = jumpCounter + 1

    hero.accel = hero.accel + 25

end

You’re proving little code so it’s hard to tell for sure, but it looks like you code says something like

“if the hero is standing on ground then add 25 to his acceleration”.

Presumably when the hero lands “onGround” is set to false or nil.

What you could is create a variable called jumpCounter (with default value zero) and use that instead of the “onGround” variable.

In the “touched” function you could then say something like:

" If jumpCounter is smaller then 2 then: add 1 to the jumpCounter and set hero.accel to hero.accel + 25".

And when then hero lands, you can set the jumpCounter to zero again.

p.s. In code that would read something like this:

if jumpCounter < 2 then

    jumpCounter = jumpCounter + 1

    hero.accel = hero.accel + 25

end