Why isn't this collision working?

local function spaceCollision(event) local phase = event.phase local target = event.target local other = event.other if phase == "began" then if other.collisionType == "eggplant" then glass.alpha = 0 physics.removeBody(glass) end end end space:addEventListener("collision", spaceCollision)

The physics.removeBody part isn’t working, when the object collides with the barrier labeled space, the glass disappears but not the the physics body, anyone know why??

You cannot remove physics body during collision this will crash game, corona prevents this by not removing body

See:https://www.dropbox.com/s/kpk9fvx2qc56z5h/Photo%20May%2010%2C%207%2004%2050%20PM.png?dl=0

If you want to remove body use a timer

Ohhh, ok, thanks

How would I remove the object using the collision, the idea is that you must collide with the object to remove a barrier so the character can get through, I used display.remove() but then I have no way of adding it back in using a button.

So basically how would I remove an object on collision and then spawn it back in using a button, using my code

Cheers

Just set physics body to sensor
I don’t even think you need a timer

glass.isSensor = true

Then just in your button put in

glass.alpha = 1
glass.isSensor = false

You cannot remove physics body during collision this will crash game, corona prevents this by not removing body

See:https://www.dropbox.com/s/kpk9fvx2qc56z5h/Photo%20May%2010%2C%207%2004%2050%20PM.png?dl=0

If you want to remove body use a timer

Ohhh, ok, thanks

How would I remove the object using the collision, the idea is that you must collide with the object to remove a barrier so the character can get through, I used display.remove() but then I have no way of adding it back in using a button.

So basically how would I remove an object on collision and then spawn it back in using a button, using my code

Cheers

Just set physics body to sensor
I don’t even think you need a timer

glass.isSensor = true

Then just in your button put in

glass.alpha = 1
glass.isSensor = false