Hi everyone,
I’ve just started using Corona SDK, and I’m having some problems applying physics on moving platforms.
Basically I have a platforms moving right to left, and when a object lands on the platform there is no friction, the object fails to move with the platform, so once the platform has moved from underneath the object, the object falls to the bottom of the screen. Has anybody else had this problem? I guess maybe a physics object loses some of its attributes but i don’t know which one.
I want that the object can move with the platform, same direction and velocity.
Here’s a code sample:
..... elements = display.newGroup() elements.anchorChildren = true elements.anchorX = 0 elements.anchorY = 1 elements.x = 0 elements.y = 0 screenGroup:insert(elements) player = display.newImageRect("player.png",30,50) player.anchorX = 50 player.anchorY = 50 player.x = 80 player.y = display.viewableContentHeight - 80 physics.addBody(player, "static", {density=.1, bounce=0.1, friction=1.0}) player:setLinearVelocity( 100, -600 ) screenGroup:insert(player) ..... .... local gameStarted = false function jumptoplatform(event) if event.phase == "began" then if gameStarted == false then player.bodyType = "dynamic" addplatformsTimer = timer.performWithDelay(1000, addplatforms, -1) moveplatformsTimer = timer.performWithDelay(2, moveplatforms, -1) gameStarted = true player:setLinearVelocity( 100, -600 ) else player:setLinearVelocity( 100, -600 ) end end end function moveplatforms() for a = elements.numChildren,1,-1 do if(elements[a].x \> -150) then elements[a].x = elements[a].x - 6 else elements:remove(elements[a]) end end end function addplatforms() platform1 = display.newImageRect("platform.png",200,80) platform1.anchorX = 0 platform1.anchorY = 1 platform1.x = 450 platform1.y = yPosition() physics.addBody(platform1, "static", {density=1, bounce=0.1, friction=1.0}) elements:insert(platform1) end .....
Maybe i have to add an onCollision function, to handle it?, or use joints? Any idea will be appreciated…
Thanks in advance