Creating an opposite impulse during post solve

Hey guys,

In my game I need a collision to occur but one of the bodies in the collision to not be affected by it. My idea was to apply an opposite impulse during each post solve to balance out each collision for the one body. Only problem is I can't figure out where to apply the opposite impulse, so far I haven't been doing it right because my bodies velocity changes after the collisions. Here's my code:

Code: Select all

void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
   {
b2WorldManifold worldManifold;
            contact->GetWorldManifold( &worldManifold );
            b2Vec2 normal = b2Vec2(worldManifold.normal.x * impulse->normalImpulses[0], worldManifold.normal.y * impulse->normalImpulses[0]);
           
            objectA.currentBody->ApplyLinearImpulse(normal, objectA.currentBody->GetLocalPoint(worldManifold.points[1]));

}


Thats my code for when objectA has the body that I don't want to be affected by the collision. Where should I apply the opposite impulse? Is there an easier way to do this?

Thank you!

Original thread: https://box2d.org/forum/viewtopic.php?t=9110