How do I remove an object once it touches another?

I’ve been messing around with this for 8+ hours and have had no luck. How do I remove an object with physics once it touches another and also add score every time it does so. I’ve tried the “physics.removeBody()” api, Collision Detection api and have been following Peach Pellen’s Score board tutorial but haven’t been able to adapt anything.
Anything, even if you just point me would be much appreciated:)
Here’s the code I’ve been using for object removal:

[code]
local function onCollision( event )
if ( event.phase == “began” ) then

– Check if body still exists before removing!
if ( spawnObject ) then
spawnObject:removeSelf()
spawnObject = nil
end

end
end
Runtime:addEventListener(“collision”, onCollision)

[import]uid: 66317 topic_id: 19113 reply_id: 319113[/import]

Hey there - give this code a go. (Plug and play, iPhone portrait.)

[lua]display.setStatusBar(display.HiddenStatusBar)

– Set up physics
require ( “physics” )
physics.start()
physics.setGravity( 0, 9 )

–The Score
local score = 0
scoreText = display.newText(score, 280, 20, “Helvetica”, 18)

–The Floor
local floor = display.newRect( 0, 460, 320, 20 )
floor.name = “floor”
physics.addBody(floor, “static”)

–Falling Objects
local function spawnCoin()
local coin = display.newCircle( 160, 50, 20 )
coin.name = “coin”
physics.addBody(coin, “dynamic”)
end
timer.performWithDelay(2000, spawnCoin, -1)

function floor:collision (event)
if event.phase == “ended” and event.other.name == “coin” then
score = score + 5
scoreText.text = score
event.other:removeSelf()
end
end
floor:addEventListener(“collision”, floor)[/lua]

Just change the score line to adjust the score system you’re using and it should give you a good starting point.

Peach :slight_smile: [import]uid: 52491 topic_id: 19113 reply_id: 73687[/import]

Thank you for the reply. That really helped!! [import]uid: 66317 topic_id: 19113 reply_id: 73695[/import]

Not a problem!

Peach :slight_smile: [import]uid: 52491 topic_id: 19113 reply_id: 73702[/import]