To know when contacts happen we can derive from b2ContactListener and implement our own solution which is great. I'm wondering is there anyway we can cancel a contact, that is to say when we hit begin contact we call a function or do something to destroy the contact before it has a chance to be resolved?

My game logic relies on setting any number of collision groups (which are basically integers). Collision groups can have settings to interact with one another, for example collision group 41 and 13 may be set to never collide while group 41 and 56 will collide. Some groups which are set not to collide are still meant to generate an OnContact callback (but will obviously never get to end contact).


Use PreSolve rather than BeginContact. From the Box2D documentation:

Pre-Solve Event

This is called after collision detection, but before collision resolution. This gives you a chance to disable the contact based on the current configuration. For example, you can implement a one-sided platform using this callback and calling b2Contact::SetEnabled(false). The contact will be re-enabled each time through collision processing, so you will need to disable the contact every time-step. The pre-solve event may be fired multiple times per time step per contact due to continuous collision detection.

|improve this answer|||||
  • \$\begingroup\$ yep that was it, I was actually trying to do b2Contact::SetEnabled(false) from inside BeginContact instead of Presolve. Moving it to presolve has worked though! \$\endgroup\$ – meds Aug 14 '11 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.