Whenever I have two dynamic bodies collide, both of them have an impulse applied and are pushed back.
What I want instead is for the movement to be stopped, with both bodies keeping the position right before the collision (so that they just touch).
I tried some stuff using b2ContactListener::BeginContact, b2FrictionJoint and using kinematic bodies instead, but none of these really did what I want.
Edit: I guess what I want is something like a kinematic body with full collisions (does not move if something else collides with it, and can collide with other bodies itself).
Hi =)
If the bodies are dynamic, you can filter the bodies that are supposed to collided with.
If you want to ignore some collision try using b2ContactFilter::ShouldCollide method.
If you want to do something specific on the bodies try using void the PostSolve(b2Contact* contact, const b2ContactImpulse *impulse); method.
Here you can identify the bodies just as you would in BeginContact method and on the body, that you want to not move, set the LinearVelocity to null vector.
If you use kinematic bodies they won't collide with other kinematic bodies and won't be affected by collisions with dynamic bodies. So I guess this is not what you want.
I hope I helped =)
Well filtering the collisions is not the issue (they should collide).
I'm pretty sure I tried resetting the speed after collisions, but the problem is that bodies are still stuck inside each other at that point.
KinematicBody is also not what I want (again, they should collide).
At the moment, I'm just hoping that I can fix this with AI (that tries to stay in place/pushes back when pushed), or maybe I will have to make a small collision library myself.
Anyway, thanks for your reply 🙂
You can disable collision reaction with b2Contact::SetEnabled
You'll need to do it every time step, because the enabled status will be reset to active every time step.
By disabling the contact and setting the velocity of the bodies to zero, I think you could get something close to what you want.
I did those things both in beginContact and endContact, pushing back other dynamicBodies just lagged a bit, but still worked. (I actually think I tried this already).
I found an excellent decision!!!
Just set body type to static at BeginContact callback of contact listener.
And set it back to dynamic after the next world step.
Also you should save and then set back linear and angular velocity of such body.