Trying to use something else than a preCollision listener with no luck. Any ideas?

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)

I might have chewed more than I could swallow. All I want to do is to make the big ball eat the smaller one… While colliding normally with different balls…

Turns out the “jump” I mentioned happens when removing one of the balls during collision. That is when the “eat” happens. Even if I remove only the physics body of the small ball that is being eaten, the big ball still jumps. I tried using timers and everything…

And the jump still happens at random times too. It is like I remove the preCollision listener for a while and they start to collide.

Hi @cbt,

Instead of creating two separate objects, I suggest you create one object with 2 bodies (a multi-element physics body). One of the elements can be a sensor, the other not (if that’s suitable for your concept). Then, just detect normal collisions (not preCollisions) and use the “index” of the body element to determine which element of the body collided.

Best regards,

Brent

I might have chewed more than I could swallow. All I want to do is to make the big ball eat the smaller one… While colliding normally with different balls…

Turns out the “jump” I mentioned happens when removing one of the balls during collision. That is when the “eat” happens. Even if I remove only the physics body of the small ball that is being eaten, the big ball still jumps. I tried using timers and everything…

And the jump still happens at random times too. It is like I remove the preCollision listener for a while and they start to collide.

Hi @cbt,

Instead of creating two separate objects, I suggest you create one object with 2 bodies (a multi-element physics body). One of the elements can be a sensor, the other not (if that’s suitable for your concept). Then, just detect normal collisions (not preCollisions) and use the “index” of the body element to determine which element of the body collided.

Best regards,

Brent