Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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).

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
    
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! –  zombinee Aug 14 '11 at 16:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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