Hi, my googling skills have failed me here on the best way to implement this behavior in Box2D.
Basically, I have two dynamic bodies (and they both need to be dynamic to have gravity, respond to external forces, etc). However, one of the bodies needs to be immovable (Body A) when the other (Body B) collides with it.
Here's what I've tried so far.
1) In PreSolve, I disabled the contact and slam the velocity of the Body B to zero. This works when Body B collides from the side, but if it's sitting on top of body A, gravity causes it to sink into Body A.
2) In PreSolve, I temporarily turn Body A into a static body and revert it back in the postsolve. All sorts of problems with this: not only does changing the body type wipe all existing kinematic state, but BodyA sinks into the ground and pops back up noticeable when transiting back to a dynamic body. This also has some crashing behavior that I've seen others mention.
3) Change all bodies to kinematic and directly pick-and-choose when velocities get applied to what. Yeah, this is fairly extreme - it sidesteps all the collision resolution goodness that Box2D has, and I haven't found the normal vectors in contact events to be accurate all the time.
Really, what I want to be able to do is alter the manifold in PreSolve such that BodyA receives no contact, but BodyB still bounces off, but distinct contact data for each fixture doesn't seem to be the model that the Manifold is working with. Any ideas?
Thanks!
Trile
Basically, I have two dynamic bodies (and they both need to be dynamic to have gravity, respond to external forces, etc). However, one of the bodies needs to be immovable (Body A) when the other (Body B) collides with it.
Here's what I've tried so far.
1) In PreSolve, I disabled the contact and slam the velocity of the Body B to zero. This works when Body B collides from the side, but if it's sitting on top of body A, gravity causes it to sink into Body A.
2) In PreSolve, I temporarily turn Body A into a static body and revert it back in the postsolve. All sorts of problems with this: not only does changing the body type wipe all existing kinematic state, but BodyA sinks into the ground and pops back up noticeable when transiting back to a dynamic body. This also has some crashing behavior that I've seen others mention.
3) Change all bodies to kinematic and directly pick-and-choose when velocities get applied to what. Yeah, this is fairly extreme - it sidesteps all the collision resolution goodness that Box2D has, and I haven't found the normal vectors in contact events to be accurate all the time.
Really, what I want to be able to do is alter the manifold in PreSolve such that BodyA receives no contact, but BodyB still bounces off, but distinct contact data for each fixture doesn't seem to be the model that the Manifold is working with. Any ideas?
Thanks!
Trile