Hello, I have been trying to avoid the double jump, I have look across many forums posts and still can’t figured it out why i cant make it to work. I have 2 problems, The first one is that i am able to double jump when I keep tapping to jump, the second is that if the character goes down and I keep tapping I can slow down the “gravity” so it takes longer for my character to get on the floor. What am i doing wrong?
local perso = display.newImage( "perso.png" ) perso:translate(0,display.contentHeight- 150) physics.addBody(perso, "dynamic", { density=1.0, friction=0,bounce=0}) perso:setLinearVelocity( 0, 0 ) local canJump = false local vx, vy = perso:getLinearVelocity() function bougerPerso(event) if event.phase == "began" and canJump==true then if event.x \>= display.contentCenterX then perso:setLinearVelocity( 200, 0 ) elseif event.x \<= display.contentCenterX then perso:setLinearVelocity( -200, 0 ) end elseif event.phase == "ended" then perso:setLinearVelocity( 0, 0 ) end end local function jump(event) if event.numTaps == 2 and canJump==true then canJump=false if event.x \>= display.contentCenterX then perso:setLinearVelocity( 100, -300 ) elseif event.x \<= display.contentCenterX then perso:setLinearVelocity( -100, -300 ) elseif perso:LinearVelocity(0 , 0 ) then perso:setLinearVelocity( 0, -300 ) end end end function perso:collision(event) if event.other.type == 'sensor' then --remove camera self.parent :kill() self:kill() pageFin() elseif event.other.unObstacle == 'plancher' then canJump = true elseif event.other.type =='portalfin' then self.parent :kill() self:kill() pageFinNiveau() end end