Explosions and Event.Force

I have created a basic explosion game where falling bombs make crates explode. I can get the bombs to explode and produce a force, but I can’t get the crate to explode. I am using the imageTable feature to create the objects which is located above this code and I know that isn’t the problem.

–BOMB 2 –

local bomb2 = movieclip.newAnim( imageTable )
bomb2.x = 260; bomb2.y = -150
physics.addBody( bomb2, { density=3.0, friction=0.4, bounce=0.2, radius=19 } )
localGroup:insert(bomb2)
bomb2:reverse{ startFrame=2, endFrame=1, loop=0 } – play specified sequence only

– Create explosion

local function onCollision ( event )
if event.phase == “began” and bomb2.y > 300 then
bomb2:play{ startFrame=3, endFrame=11, loop=1, remove=true }
audio.play( bombSound )
bomb2:applyForce( 3000, 3000, bomb.x - 10, bomb.y )
end
end
Runtime:addEventListener( “collision”, onCollision )

–CRATE 1–

imageTableCrate = {}
for i = 1,2 do
table.insert( imageTableCrate, “images/crate” … i … “.png” )
end
for i = 1,9 do
table.insert( imageTableCrate, “images/explode” … i … “.png” )
end

local crate = movieclip.newAnim( imageTableCrate )
crate.x = 220; crate.y = 440; crate.id = “crate”
physics.addBody( crate, { density=0.2, friction=0.1, bounce=0.5 } )
localGroup:insert(crate)
crate:reverse{ startFrame=2, endFrame=1, loop=0 } – play specified sequence only

–Everything works until I get here!–

local function onCollision ( event )
print( "force: " … event.force )
if ( event.force > 1.0 ) then
crate:play{ startFrame=3, endFrame=11, loop=1, remove=true }
audio.play( bombSound )
crate:applyForce( 3000, 3000, crate.x, crate.y )
end
end
Runtime:addEventListener( “collision”, onCollision )
[import]uid: 32061 topic_id: 6246 reply_id: 306246[/import]

is that all in the same file? [import]uid: 6645 topic_id: 6246 reply_id: 21508[/import]

Yes. along with other things. [import]uid: 32061 topic_id: 6246 reply_id: 21510[/import]

Figured it out. NM [import]uid: 32061 topic_id: 6246 reply_id: 21543[/import]

It would be nice to share the code after you figured it out for the community to learn from [import]uid: 22737 topic_id: 6246 reply_id: 21552[/import]

The problem was that I was using Runtime instead of the object (ie bomb and crate) so the function was hitting all of them instead of the specific object I wanted.

crate:addEventListener( “postCollision”, onPostCollision ) [import]uid: 32061 topic_id: 6246 reply_id: 21557[/import]