Hello,
In my project I have some objects. I want those objects to interact with others but not with itself. But I also need collision info while it collides with itself.
So I changed my collision filters to make it interact with itself and I added preCollision listeners like to disable only the collisions with itself (e.contact.isEnabled). But for some reason, it sometimes pushes bodies apart while they are on top of each other, in a split second. Not always but it happens.
So I ditched preCollisions idea to make something like a ‘collision sensor’ that glued on top of my objects shaped exactly like the object. I created it with isSensor = true, changed it size accordingly, and put it inside the object’s display group. But when listening to events I get weird results. I couldn’t get the listener to pick up events.
What should my approach be do you think? I can make it work with a global listener but I want to keep to local listeners for this.
A little bit of code:
objectDG = display.newGroup() --my object object = display.newImage(...) --a circle image sensor = display.newCircle(0, 0, 10) -- my sensor physics.addBody(sensor) sensor.isSensor = true physics.addBody(objectDG) objectDG:insert(object) objectDG:insert(sensor) object.collision = MyCollisionListener sensor:addEventListener("collision", object.collision) object:addEventListener("collision", object.collision)