How can I make my physics object in my game jump, without it coming straight down after moved?
Also this does not work from some reason, what I mean by that it is so that that function down there does not limit jumps. You can jump unlimited times. I would like to fix that.
local function movePlayer() motionx = 0 -- Variable used to move character along x axis speed = 5 -- Set Walking Speed local function moveLeft(event) if "began" == event.phase then motionx = - speed animation.xScale = -1 end if "ended" == event.phase then motionx = 0 end end local function moveRight(event) if "began" == event.phase then motionx = speed animation.xScale = 1 end if "ended" == event.phase then motionx = 0 end end local function moveUp(event) if "began" == event.phase and animation.canJump == 0 then transition.to(animation, {time = 750, y = animation.y - 100}) end end function charCollide( self,event ) if ( event.selfElement == 2 and event.other.objType == "ground" ) then if ( event.phase == "began" ) then self.canJump = self.canJump+1 elseif ( event.phase == "ended" ) then self.canJump = self.canJump-1 end end end animation.collision = charCollide animation:addEventListener("collision", animation) local function moveguy(event) --map.updateView() animation:setLinearVelocity(motionx \* 40, 0) map.positionCamera(animation.x - \_W / 15, animation.y) animation.rotation = 0 end Runtime:addEventListener("enterFrame", moveguy) leftButton:addEventListener("touch", moveLeft) rightButton:addEventListener("touch", moveRight) jumpButton:addEventListener("touch", moveUp) end movePlayer()
Thanks for your time