How to make the player jump on a platform game

Hi. I’m trying to get my jump function to work, it does kinda. When the player is standing still it jumps just fine, but when I try to jump and then move, the player floats down slowly at an angle, and while i’m moving and then I try to jump, it jumps, but then almost insistently stops like it hit a wall, and falls back down.

I have multi touch enabled; and i’m using widgets for my control buttons  

Here’s the code:

[lua]

local function moveKnightRight(event)

if(event.phase == “began”) then

display.getCurrentStage( ):setFocus(rightButton, event.id);

function canMoveRight()

if (knight.x < _W + 30) then

knight:setLinearVelocity( 100, 0 )

else

knight:setLinearVelocity( 0, 0 )

end

end

knight.xScale = 1

knight:setSequence(“moving”)

knight:play()

sword.xScale = 1

sword.rotation = 40

playerTable.dir = “right”

Runtime:addEventListener(“enterFrame”, canMoveRight)

elseif (event.phase == “ended” or event.phase == “cancelled”) then 

display.getCurrentStage( ):setFocus(event.target, nil);

Runtime:removeEventListener(“enterFrame”, canMoveRight)

knight:setLinearVelocity( 0, 0 )

knight:setSequence(“still”)

end

end–moveKnightright

– Jump function

local function jumpFunc(event)

if(event.phase == “began” and knight.sensorOverlaps > 0 ) then

display.getCurrentStage( ):setFocus(jumpButton, event.id);

local vx, vy = knight:getLinearVelocity()

        knight:setLinearVelocity( vx, 0 )

        knight:setLinearVelocity( nil, -150 )

elseif (event.phase == “ended” or event.phase == “cancelled”) then 

display.getCurrentStage( ):setFocus(event.target, nil);

end

end–jumpFunc

local function sensorCollide( self, event )

– Confirm that the colliding elements are the foot sensor and a ground object

if ( event.selfElement == 2 and event.other.objType == “ground” ) then

– Foot sensor has entered (overlapped) a ground object    

if ( event.phase == “began” ) then

self.sensorOverlaps = self.sensorOverlaps + 1

   

– Foot sensor has exited a ground object    

elseif ( event.phase == “ended” ) then

self.sensorOverlaps = self.sensorOverlaps - 1

   

end

end

end–sensorCollide

– Associate collision handler function with character

knight.collision = sensorCollide

knight:addEventListener( “collision” )

[/lua]

Never mind. Fixed it.

Never mind. Fixed it.