Weird 'Bounce' Behaviour

I’ve built a game similar to Doodle Jump. My character jumps up through platforms and then jumps when he comes down on top of them.

I am experiencing some very strange behaviour with his jumps though. If the character is just jumping on the spot on the same platform then he always goes the same height. The issue occurs when the character jumps through the bottom of one platform and ontop of another, the character seems to jump far far higher than he should. This is making the game quite unplayable, as the rest of the game can’t keep up with it. The height is about double what it should be.

My code for the jump is:

local function onPlatformCollision( event ) vx, vy = man:getLinearVelocity() if vy \> 0 then man:setLinearVelocity( 0, 0 ) man:applyLinearImpulse(0, -0.6, man.x, man.y) end end
I thought I was stopping the man from moving with setLinearVelocity(), but I’m not sure this is working because I would have thought man:setLinearVelocity( 0, 0 ) would stop him moving horizontally aswell as vertically, but it doesn’t - the character just moves freely.

Am I missing something?

Any help appreciated as always :slight_smile: [import]uid: 61422 topic_id: 15444 reply_id: 315444[/import]

setLinearVelocity will actually stop all the movement. so every jump will be of equal height. you can see that on the below example. the character will keep on jumping with same velocity…if you need to get a different behavior you should set the impulse accordingly.
see the sample below
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,9.8)

local jumpPlatform = display.newRect( 120, 350, 60, 5 )
physics.addBody( jumpPlatform, “static”, { friction=0.3,isSensor = true} )

local jumpPlatform2 = display.newRect( 120, 280, 60, 5 )
physics.addBody( jumpPlatform2, “static”, { friction=0.3,isSensor = true} )

local jumpPlatform3 = display.newRect( 120, 210, 60, 5 )
physics.addBody( jumpPlatform3, “static”, { friction=0.3,isSensor = true} )
local ball = display.newCircle(150,410,10)
physics.addBody( ball, “dynamic”, { friction=0.2,density = .8} )

local function onFloorCollision( event )
vx, vy = ball:getLinearVelocity()
if vy > 0 then
ball:setLinearVelocity( 0, 0 )
ball:applyLinearImpulse(0, -3, ball.x, ball.y)
end
end

jumpPlatform:addEventListener( “collision”, onFloorCollision )
jumpPlatform2:addEventListener( “collision”, onFloorCollision )
jumpPlatform3:addEventListener( “collision”, onFloorCollision )
ball:applyLinearImpulse(0, -3, ball.x, ball.y) [/lua] [import]uid: 71210 topic_id: 15444 reply_id: 57123[/import]