Take a static body and add a circle fixture. Take a dynamic body "above" the static body also with a circle fixture but set that as a sensor. Let the dynamic body fall until it contacts the static circle fixture.
What I find is that the BeginContact reported to my collision listener occurs after the circle fixtures overlap (I'm not talking about their respective AABB). If neither fixture is a sensor then the BeginContact is reported when they overlap.
When I trace the Box2D code I see that a contact is generated when the two shape AABB overlap as expected however, because one shape is a sensor, the contact is only reported to the contact listener (BeginContact) here during the b2World::step()
This is done *prior* to the solve. In other words, sensor contacts are generated *after* this but won't be reported until you call step again. This is not the case where a fixture is not a sensor because here after the solve:
... any contacts that are overlapping will be reported to the contact listener. The problem however is that there's the following line in the TOI calculation to skip sensors:
... which means any sensors overlapping won't get reported until the next step!!
You can't remove this line but you can add an explicit call to update the contact like this:
... which works. Now I get collision contacts reporting at the same time I get sensor contacts. My problem is that I'm not sure this is the best solution. I suspect what I need to do is in-between the Solve and SolveTOI is perform an iteration of the existing contacts and explicitly call updates for contacts involving sensors.
This is actually a very subtle effect and easy to miss because you will get sensor contacts reported to BeginContact however this is during the next call to b2World::Step().
Thoughts?
What I find is that the BeginContact reported to my collision listener occurs after the circle fixtures overlap (I'm not talking about their respective AABB). If neither fixture is a sensor then the BeginContact is reported when they overlap.
When I trace the Box2D code I see that a contact is generated when the two shape AABB overlap as expected however, because one shape is a sensor, the contact is only reported to the contact listener (BeginContact) here during the b2World::step()
Code:
// Update contacts. This is where some contacts are destroyed.
{
b2Timer timer;
m_contactManager.Collide(); <--- This ends-up reporting all contacts involving sensors.
m_profile.collide = timer.GetMilliseconds();
}
{
b2Timer timer;
m_contactManager.Collide(); <--- This ends-up reporting all contacts involving sensors.
m_profile.collide = timer.GetMilliseconds();
}
This is done *prior* to the solve. In other words, sensor contacts are generated *after* this but won't be reported until you call step again. This is not the case where a fixture is not a sensor because here after the solve:
Code:
// Handle TOI events.
if (m_continuousPhysics && step.dt > 0.0f)
{
b2Timer timer;
SolveTOI(step);
m_profile.solveTOI = timer.GetMilliseconds();
}
if (m_continuousPhysics && step.dt > 0.0f)
{
b2Timer timer;
SolveTOI(step);
m_profile.solveTOI = timer.GetMilliseconds();
}
... any contacts that are overlapping will be reported to the contact listener. The problem however is that there's the following line in the TOI calculation to skip sensors:
Code:
// Is there a sensor?
if (fA->IsSensor() || fB->IsSensor())
{
continue;
}
if (fA->IsSensor() || fB->IsSensor())
{
continue;
}
... which means any sensors overlapping won't get reported until the next step!!
You can't remove this line but you can add an explicit call to update the contact like this:
Code:
// Is there a sensor?
if (fA->IsSensor() || fB->IsSensor())
{
c->Update(m_contactManager.m_contactListener);
continue;
}
if (fA->IsSensor() || fB->IsSensor())
{
c->Update(m_contactManager.m_contactListener);
continue;
}
... which works. Now I get collision contacts reporting at the same time I get sensor contacts. My problem is that I'm not sure this is the best solution. I suspect what I need to do is in-between the Solve and SolveTOI is perform an iteration of the existing contacts and explicitly call updates for contacts involving sensors.
This is actually a very subtle effect and easy to miss because you will get sensor contacts reported to BeginContact however this is during the next call to b2World::Step().
Thoughts?