Really simple question regarding collisions

Basically there is a falling object that I want to be removed once it hits the floor. Would I do

floor:addEventListener (“collision”, collisionDetector) and would I have to specify what to do if obj1 hits the ground vs obj2?

Or maybe I should add the event listener to obj1? Any help will be greatly appreciated. [import]uid: 35535 topic_id: 9253 reply_id: 309253[/import]

you can try something like this.

Note: I haven’t tested the code, but this should give you an idea
[lua]local obj1
local obj2
– define your obj2 here as the floor…
– define the collision function first
local onCollide = function (self, event)
if event.phase == “began” then

– do something, example: explosion or something
print(“explosion”)

– remove the obj1, self is referring back to obj1
self:removeSelf()
self = nil

end
end

obj1 = display.newRect(0,0,50,50)
obj1:setFillColor(200,0,0,255)
obj1.x = 240
obj1.y = 20
physics.addBody(obj1, “dynamic”, {density = 1})
obj1.collision = onCollide
obj:addEventListener(“collision”, onCollide)

[import]uid: 12455 topic_id: 9253 reply_id: 33749[/import]