Moving objects together..

When i drop objects on moving platforms (moving on x axis only…), dragged object doesn’t move with platform… Have any suggestions? :slight_smile:

Moving platform’s code;

[lua]function Objects:mBlockWide( posX , posY , toX, toY, mtime)

mblock = display.newImageRect( “Images/widePlatform.png”, 145, 6 )
mblock.x = posX
mblock.y = posY

function getBack()
transition.to( mblock, { time=mtime, alpha=1, x=posX, y=posY, onComplete=moveForward } )
end

function moveForward()
transition.to( mblock, { time=mtime, alpha=1, x=toX, y=toY, onComplete=getBack } )
end

physics.addBody( mblock, “static”, { friction=0.5, bounce=0.3 } )
moveForward()

return mblock
end[/lua]

Dropped objects code;

[lua]function Objects:box( posX , posY )
box = display.newImageRect( “Images/box.png”, 34, 34 )
box.x = posX
box.y = posY
box.isFixedRotation = true
physics.addBody( box, { density=3.0, friction=0.5, bounce=0.3 } )
box:addEventListener( “touch”, startDrag )
return box
end [/lua]

Thanks for your help… :slight_smile:
[import]uid: 14440 topic_id: 6228 reply_id: 306228[/import]

Clarify
You have a box that you drag on the screen and when you let it go you want it to fall down onto the moving background and as other objects move together with the background? [import]uid: 22737 topic_id: 6228 reply_id: 21390[/import]

Yes, exactly. [import]uid: 14440 topic_id: 6228 reply_id: 21401[/import]

Hey
When you box collide with the moving background object I would guess you need to set the bodyType of the box to static or kinematic so it gets stuck to that object.

The other solution would be to draw a 1 pixel line at the bottom of the screen and then add your background object as dynamic on top of that static 1 pixel line with a superhigh density. Then you box as that is also dynamic it will get on the moving background and move as well.

My best tip would be solution 2, add a static body at the bottom and then put your body on top of that line and give it dynamic as bodyType with high density of maybe around 20 so that it would not be able to move or slide on top of the line.

It seems like this is not as straight forward as a lot of other stuff in Corona. I would also tip you of the Lime library and together with the free tool Tiled Map Editor you can do 2D platforms extremely easy and add properties like density, bounce, friction and more to objects inside map editor and with the Lime library your Corona project will read thoose properties and just make things work.

www.justaddli.me [import]uid: 22737 topic_id: 6228 reply_id: 21431[/import]