Physics and moving platforms

I have a game where a character is jumping onto moving platforms. The platforms are “bouncy” so the character should bounce off them when he lands on one.

Everything works well UNLESS the character falls down onto a platform that is also moving down - then the character sticks to the platform until it stops, then it seems to receive a large impulse force.

Sample code shown below, if you change the “animated” variable on line 6 from true to false, you will see the bounce works.

Is this a bug or am I doing something wrong??

[lua]local physics = require( “physics” )
physics.start()

local world = display.newGroup()
local moveY=0
local animated=true

local ei=display.newRect( world, 0, 0, 20, 100 )
ei:setFillColor(0,255,0)
ei.x=display.contentWidth/2
ei.y=display.contentHeight/2-200
physics.addBody( ei, { bounce=1, friction=0.1 } )
ei.isFixedRotation = true

local platform=display.newRect( world, 0, 0, 100, 20 )
platform:setFillColor(255,0,0)
physics.addBody( platform,“static”, { bounce=1, friction=0.1 } )
platform.x=display.contentWidth/2
platform.y=display.contentHeight/2

function mainloop()

if (animated and moveY<100) then
platform.y=platform.y+1
moveY=moveY+1
end

end

Runtime:addEventListener(“enterFrame”, mainloop)
[import]uid: 73098 topic_id: 12321 reply_id: 312321[/import]

I think I had the same problem when I tried to move a static object with transitions. Try changing the bodyType of the platform to kinematic and moving it with setLinearVelocity function. [import]uid: 13507 topic_id: 12321 reply_id: 44887[/import]

Thanks, that didn’t totally solve the problem but it helped a lot.

For others who have a similar problem, here’s a solution. The platform is changed to Kinematic AND the character is set to be treated as a bullet. The combination of the two changes, seems to fix the problem.

[lua]local physics = require( “physics” )
physics.start()

local world = display.newGroup()
local moveY=0
local animated=true

local ei=display.newRect( world, 0, 0, 20, 100 )
ei:setFillColor(0,255,0)
ei.x=display.contentWidth/2
ei.y=display.contentHeight/2-200
physics.addBody( ei, { bounce=1, friction=0.1 } )
ei.isFixedRotation = true
ei.isBullet=true
local platform=display.newRect( world, 0, 0, 100, 20 )
platform:setFillColor(255,0,0)
physics.addBody( platform,“kinematic”, { bounce=1, friction=0.1 } )
platform.x=display.contentWidth/2
platform.y=display.contentHeight/2
platform:setLinearVelocity( 0, 20 )

function mainloop()

if (animated and moveY<200) then
moveY=moveY+1
else
platform:setLinearVelocity( 0, 0 )
animated=false
end

end

Runtime:addEventListener(“enterFrame”, mainloop)
[import]uid: 73098 topic_id: 12321 reply_id: 44899[/import]