Help destroying object

Hi. What I was doing is basically doing is having a box that shoots bullets and goes down. My problem that I’ve been trying to solve is how to have the box be destroyed when it comes to contact with the floor.

Here is the plug snd play code to see the problem

[code]local physics = require( “physics” )
physics.start()

local box3 = display.newRect(160, 100, 30, 30)
physics.addBody(box3, “static”,{density = 0, bounce = 0.3, friction = 0})

local box2 = display.newRect(0, 470, 320, 30)
box2.hit = “box2”
physics.addBody(box2, “static”,{density = 0, bounce = 0, friction = 0})

local function bullet (event)
bull = display.newRect(200, 240, 30, 30)
bull.x = box3.x + 50
bull.y = box3.y + 15
transition.to (bull, {time=3000, y=550})
physics.addBody(bull,{density = 0, bounce = 0.3, friction = 0})
bull:addEventListener(“collision”, bull)

function bull:collision (event)
if event.other.hit ~= “box2” then
bull:removeSelf()
end
end
end
timer.performWithDelay(1000, bullet, -1) [/code]

I’ve been trying for hours to try and figure out how to remove the bullet on collision with ground. Any one please help is appreciated :slight_smile: [import]uid: 17058 topic_id: 22055 reply_id: 322055[/import]

Line 20 should be;
[lua]if event.other.hit == “box2” then[/lua]

You were saying ~= which means NOT equal to.

Peach :slight_smile: [import]uid: 52491 topic_id: 22055 reply_id: 87633[/import]

@peach almost forgot thanks for the help :slight_smile: [import]uid: 17058 topic_id: 22055 reply_id: 87689[/import]