Hi there,
You’ll need to implement a pre-collision listener on the objects to stop the physics engine from allowing them disturb each other when they collide. To do that, you set event.contact.isEnabled to false inside the pre-collision listener.
A simple listener would look something like this…
local function preCollision(self, event) --Ignore non-contact events if (event.contact==nil) then return end --Get the other object involved in the collision... local object = event.other --Tell Box 2D to ignore objects with the 'ghost' property. if (object.ghost) then event.contact.isEnabled=false end end
Now add the ghost property to your two objects.
object1.ghost=true object2.ghost=true
And finally add the pre-collision listener to your objects.
Add pre-collision listener to object 1 object1.preCollision = onPreCollision object1:addEventListener("preCollision", object1) --Add pre-collision listener to object 2 object2.preCollision = onPreCollision object2:addEventListener("preCollision", object2)
Note that Corona will still fire collision events for the two objects when they hit each other, so you can take appropriate action when they do. Setting event.contact.isEnabled to false just makes sure they don’t disturb each other when they do hit.
There’s a full explanation of pre-collision events here: https://docs.coronalabs.com/api/event/preCollision/index.html
And a general tutorial on collisions here: https://docs.coronalabs.com/guide/physics/collisionDetection/
And this explanation is useful too: https://coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/