Sensors + high speed bodies and restitution hacks

Hi folks,

I'm trying to use sensors to help me trigger events when a high speed body enters an area. I only wish to trigger my event when the body is sufficiently inside the sensor region so have found myself having to use the

Persist()

callback in the contact listener rather than the

Add()

function. This works fine for bodies moving with a reasonable speed, but high speed bodies are seemingly able to be in the sensor perhaps only once for the Add() but never persisting. I'm assuming the continuous collision detection only happens when the geometry is not a sensor?

To try and fix this i'm able to enclose the sensor inside a set of normal static bodies to try and catch any high speed bodies from passing through in one frame, frustratingly due to restitution being evaluated as the max of the two colliding bodies restitutions i'm unable to let these bodies absorb most if not all the high speed bodies velocity and then let them exist inside the sensor ready to trigger my event.

What are the options for fixing this? Is there an option i can turn on that will let the sensors benefit from the continuous collision detection so that they don't miss a high speed body passing through it. Or can i possibly enable some option so that my enclosing shapes can enforce a very very low restitution to absorb all the high speed bodies velocity as i described.

Cheers

Jim
I guess one other option is for me to artificially shrink the sensor shape to enforce my penetration requirements on the current size and then i'll be able to just use the add() contact listener and presumably that will ALWAYS be called regardless of the speed of the body?
Yeah, that would be much better than your current way. Saying you are listening for persists just means you are waiting one frame after the collision to do anything, which obviously isn't the same. If you are only concerned with shallow penetrations, I think that the Add and Persist events provide a penetration depth you could use.
I've only just had chance to experiment with this problem, and unfortunately its still an issue.

Namely i've now changed my code to use smaller sensors, and then do all my work within the contact listeners

Add()

sadly though this is still not actually being called if the body in question is moving at high speed.

I take it there should be no exceptions to this, and that the continuous physics should be catching it regardless of speed?

The dynamic bodies are set as bullets, but i've tried turning that off and its made no difference, as you'd expect.
Box2D does not check for contacts with sensors until the end of the frame. There might be a good reason for this, but I don't know what it would be, aside from optimization. It's true that continuous physics resolution doesn't make sense between sensors and bullets, since the sensors don't actually collide with the bullets anyway, but anyone who creates sensors has almost certainly created a contact listener too and probably wants to be notified of the contact. In the Flash version I have tried enabling continuous contact detection between bullets and sensors and it didn't immediately break anything and appeared to function as intended:
viewtopic.php?f=8&t=1571

Erin Catto, of course, would know more.
thank you for your reply. I'll look into that.

It is the actionscript version of box that i'm working in, but i posted here as when first posting it was a general question about box2d. I am not sure what the protocol on this is, i'd presume using my own judgement as to its relevance and posting accordingly?

I was about to post to say as much and post about this in the actionscript thread.

Cheers
thanks. The hacked b2world.as has fixed the problem. I'll look for doors blowing off. May add a way of having the app decide if it wants to use this hack, well if another app hits a problem then i'll add it at that point.

They'll be a reason why it wasn't enabled by default, or perhaps it was a performance optimisation?

Cheers though. It works!!! 🙂
Erin works in mysterious ways, but unlike god, there usually turns out to be a good reason for it in the end. I had thought sensors plus bullets was nonsensical, as the bullets velocity is unaffected by the sensors, so would collide with it repeatedly, hanging the substeps. But evidently the internal collision flags remmember enough to avoid this, or else that hack would fail immediately...

Original thread: https://box2d.org/forum/viewtopic.php?t=1464