Hi all,
I'm developing a game with a massive number of collisions.
My game is quite complex so I'm getting the contacts within box2d bodies and I'm facing a quite weird issue, that is, the contacts are created far before the bodies collide.
To fix that, I'm currently using b2TestOverlap checking that the bodies are really colliding and if not I just ignore the contact.
As you can imagine this causes performance problems that I'd like to avoid.
Is there any reason why contacts have been constantly created even if there is no collision? And how can I avoid it?
This is my code:
Thanks a lot!
I'm developing a game with a massive number of collisions.
My game is quite complex so I'm getting the contacts within box2d bodies and I'm facing a quite weird issue, that is, the contacts are created far before the bodies collide.
To fix that, I'm currently using b2TestOverlap checking that the bodies are really colliding and if not I just ignore the contact.
As you can imagine this causes performance problems that I'd like to avoid.
Is there any reason why contacts have been constantly created even if there is no collision? And how can I avoid it?
This is my code:
Code:
for (b2ContactEdge* ce = _body->GetContactList(); ce; ce = ce->next) {
b2Contact* c = ce->contact;
b2Fixture *fixtureA = c->GetFixtureA();
b2Fixture *fixtureB = c->GetFixtureB();
//checking if they overlap
if (!b2TestOverlap(fixtureA->GetShape(), fixtureB->GetShape(),
fixtureA->GetBody()->GetTransform(), fixtureB->GetBody()->GetTransform())) {
continue; //they don't => ignore contact
}
...
}
b2Contact* c = ce->contact;
b2Fixture *fixtureA = c->GetFixtureA();
b2Fixture *fixtureB = c->GetFixtureB();
//checking if they overlap
if (!b2TestOverlap(fixtureA->GetShape(), fixtureB->GetShape(),
fixtureA->GetBody()->GetTransform(), fixtureB->GetBody()->GetTransform())) {
continue; //they don't => ignore contact
}
...
}
Thanks a lot!