Help on making a character double jump?

Hey I need help with controlling jump. Ok what I want it when the character jump he can double jump in midair, and not any further than that.

Here is the code below

[code]display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()

local background = display.newImage( “background.jpg” )

local ground = display.newImage( “ground.png” )
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 320

local groundShape = { -240,-20, 240,-20, 240,20, -240,20 }
physics.addBody( ground, “static”, { friction=1.0, density=1.0, bounce=0, shape=groundShape } )

local character = display.newImage( “character.png” )
character.x = 70
character.y = 230

physics.addBody( character, { friction=1.0, density=1.0, bounce=0.3, radius=35 } )
character.isFixedRotation = true

local function onScreenTouch( event )
if event.phase == “began” then
– make character jump forward
character:applyForce( 400, -2100, character.x, character.y )
end

return true
end

Runtime:addEventListener( “touch”, onScreenTouch ) [/code]

The problem with the above code is he jumps in midair and basically you click on the background as many time and it would not stop going up. I just want my character to double jump for the code above.

Help is appreciated :slight_smile: [import]uid: 17058 topic_id: 21397 reply_id: 321397[/import]

Try making a local variable;

[lua]local jumpCount = 0[/lua]

Then in onScreenTouch do;
[lua]jumpCount = jumpCount + 1
if jumpCount < 2 then
–jump logic here[/lua]

That way it will only jump twice.

Of course this will only work one time as it is - so you would need to set jumpCount = 0 when your player landed back on the ground so that he could then double jump again.

Peach :slight_smile: [import]uid: 52491 topic_id: 21397 reply_id: 84733[/import]

@peach thanks alot I got now I got it working [import]uid: 17058 topic_id: 21397 reply_id: 84766[/import]

No worries Sebitttas, happy to help :slight_smile: [import]uid: 52491 topic_id: 21397 reply_id: 84882[/import]