spawned objects on a movable platform

I am spawning randomly colored and sized blocks, thusly:
[blockcode]
function createBoxes()
local function randBox()
local randW = mRand(60, 80)
local randH = randW
local genY = (-100)
local genX = mRand(100, 300)
local red = mRand(1, 245)
local green = mRand(1, 245)
local blue = mRand(1, 245)
local newBox = display.newRoundedRect (genX, genY, randW, randH, 10)
physics.addBody(newBox, “dynamic”, {friction=1, bounce=.05, density=3})
newBox.myName = “box”
newBox.strokeWidth = 5
newBox:setFillColor(red, blue, green)
newBox:addEventListener(“collision”, onCollision)
end
timer.performWithDelay(2000, randBox, 10)
end
[/blockcode]

These blocks fall on a platform that will eventually be moved via accelerometer. This is the code for the platform:
[blockcode]
function createDeck()

local deckHeight = 10
local deckWidth = _W/2
local motionx = 0
local motiony = 0

local deck = display.newRoundedRect(_W/2 - deckWidth/2, _H * .75, deckWidth, 10, 2)
physics.addBody(deck, “static”, {friction=.75, bounce=0.01, density=3})
deck.myName = “deck”
–using touch for testing
local function moveDeck(event)
deck.x = event.x
end

Runtime:addEventListener(“touch”, moveDeck)
[/blockcode]

The blocks interact with gravity and physics correctly (they hit the platform and bounce). I am having trouble figuring out how to get the blocks to move with the platform and each other once they land on it.
[import]uid: 55934 topic_id: 13864 reply_id: 313864[/import]

We’ve been having the same problem.

I see you’re using an event listener to check when the boxes hit the stand.

 newBox:addEventListener("collision", onCollision)  

Thing is you can’t modify the objects whilst the physics engine is acting upon them, so you can’t create weld joints upon a collision. We tried this, and the simulator crashed every time.

You’ll get weird bugs with the stand, as you have defined it as a physics object but are moving it around without the use of physics. It’s what we’re trying to sort out now. [import]uid: 68741 topic_id: 13864 reply_id: 50971[/import]

I would use body:applyLinearImpulse( ) to move the platform which will allow you to “push” the platform at any time. Assuming the platform and the crates have friction, any crates on top of the platform will also move in the same direction.
[import]uid: 49842 topic_id: 13864 reply_id: 50979[/import]

How would I get that to work with the accelerometer? [import]uid: 55934 topic_id: 13864 reply_id: 50984[/import]

sorry, I haven’t used the accelerometer yet so don’t have code.
do a google search for corona accelerometer and loads of sample code pops up.
more info for body:applyLinearImpulse is at http://developer.anscamobile.com/reference/index/bodyapplylinearimpulse [import]uid: 49842 topic_id: 13864 reply_id: 50986[/import]