Hello Box2D community,
I've hit a bit of a snag. I've got 2 fixtures which I'm able to detect but once the initial detection has been made, I want to stop collision on those 2 objects. It's comparable to dropping a box onto the ground and once the box hits the ground, I would like the initial contact to be noted but all further occurrences between those 2 specific objects to stop. What I'm getting however, is constant detection between the 2 objects as my ContactListener container holding the 2 fixtures continues to loop away. This is what I have in my contact listener:
I thought by setting filter data to -8 on both fixtures at the end of the Contact, I'd be able to achieve what I'm after but this doesn't work. Some guidance on this would be much appreciated.
I've hit a bit of a snag. I've got 2 fixtures which I'm able to detect but once the initial detection has been made, I want to stop collision on those 2 objects. It's comparable to dropping a box onto the ground and once the box hits the ground, I would like the initial contact to be noted but all further occurrences between those 2 specific objects to stop. What I'm getting however, is constant detection between the 2 objects as my ContactListener container holding the 2 fixtures continues to loop away. This is what I have in my contact listener:
Code:
void MyContactListener::BeginContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
_contacts.push_back(myContact);
}
void MyContactListener::EndContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
std::vector<MyContact>::iterator pos;
pos = std::find(_contacts.begin(), _contacts.end(), myContact);
if (pos != _contacts.end()) {
_contacts.erase(pos);
}
b2Filter filter1 = myContact.fixtureA->GetFilterData();
b2Filter filter2 = myContact.fixtureB->GetFilterData();
filter1.groupIndex = -8;
filter2.groupIndex = -8;
myContact.fixtureA->SetFilterData(filter1);
myContact.fixtureB->SetFilterData(filter2);
}
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
_contacts.push_back(myContact);
}
void MyContactListener::EndContact(b2Contact* contact) {
MyContact myContact = { contact->GetFixtureA(), contact->GetFixtureB() };
std::vector<MyContact>::iterator pos;
pos = std::find(_contacts.begin(), _contacts.end(), myContact);
if (pos != _contacts.end()) {
_contacts.erase(pos);
}
b2Filter filter1 = myContact.fixtureA->GetFilterData();
b2Filter filter2 = myContact.fixtureB->GetFilterData();
filter1.groupIndex = -8;
filter2.groupIndex = -8;
myContact.fixtureA->SetFilterData(filter1);
myContact.fixtureB->SetFilterData(filter2);
}
I thought by setting filter data to -8 on both fixtures at the end of the Contact, I'd be able to achieve what I'm after but this doesn't work. Some guidance on this would be much appreciated.