Reputation: 654
I am using libGDX with box2D, and I have two bodies who has collision filtering so they cant collide each other.
I am using the groupIndex filter for those bodies, so you can imagine.
But i want to detect the body collision with the contact listener even if they cant collide to each other.
There is a way to do it?.
I did not put any code because this is a question and i thought is not necessary, at least for now...
If you can help me, thank you!.
Upvotes: 0
Views: 749
Reputation: 1815
Use Contact setEnabled
method.
In ContactListener:
@Override // In preSolve method. Not beginContact, it matters
public void preSolve(Contact contact, Manifold manifold) {
short firstBit = contact.getFixtureA().getFilterData().categoryBits;
short secondBit = contact.getFixtureB().getFilterData().categoryBits;
if ((firstBit | secondBit) == (BOX_BIT | GROUND_BIT)) {
System.out.println("Contact " + firstBit + " " + secondBit);
contact.setEnabled(false);
}
}
These bits BOX_BIT
and GROUND_BIT
are bits of your bodies that shouldn't collide but ContactListener will catch contact between them, set it like:
fixturedef.filter.categoryBits = GROUND_BIT;
Set some other bit for bodies that they should collide.
Hope helps.
Upvotes: 1