bullet3 icon indicating copy to clipboard operation
bullet3 copied to clipboard

btDiscreteDynamicsWorld applies damping to inactive bodies

Open esoma opened this issue 2 years ago • 0 comments

When using btDiscreteDynamicsWorld bodies which are not active (as in btCollisionObject::isActive) have btRigidBody::applyDamping executed. For sleeping bodies this isn't really a big deal (a waste of cycles perhaps), but for bodies with DISABLE_DEACTIVATION this has led to unexpected behavior (to me at least) where a body is deactivated while it has velocity and then when later activated it has lost velocity.

I believe the problem is: https://github.com/bulletphysics/bullet3/blob/dc72081eb19831e5b28b071dc76ec51fc1fe9451/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp#L1091-L1106

For comparison btSimpleDynamicsWorld checks if the body is active before applying damping: https://github.com/bulletphysics/bullet3/blob/101c98cfb8fd297ebae6007fd10619f74c4a9748/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp#L208-L228

I've applied the same logic found in btSimpleDynamicsWorld to btDiscreteDynamicsWorld and it fixes the issue. Happy to put up a PR.

This probably also affects btDiscreteDynamicsWorldMt, though I haven't tried it: https://github.com/bulletphysics/bullet3/blob/5ae9a15ecac7bc7e71f1ec1b544a55135d7d7e32/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorldMt.cpp#L192-L210

esoma avatar Mar 03 '22 22:03 esoma