Fixed Rigidbodies not sleeping

Options
Seems that rigidbody sleep was disabled, I assume so that it could be 'fixed later' - because when I re-enabled it, it was broken.

To re-enable sleeping, I set AllowDeactivation to true in World.

This didn't work right away - the body would sleep for a few frames then wake up, then sleep, then wake up.

When the body is put to sleep, body.inactiveTime is set to FP.PositiveInfinity. The issue was that body.inactiveTime was being incremented by timestep even when the body was already asleep. Then, the next frame, body.inactiveTime += timestep causes inactiveTime to overflow and wrap back around to FP.MIN_VALUE, which woke the rigidbody.

The other issue was that, once asleep, the only thing that could wake the rigidbody was a collision. I made sure that adding any forces/impulses/torque to the rigidbody causes it to wake up.

You can find the changes I made here:
https://bitbucket.org/pelicanpunch/truesync/commits/d66f29397ff9cf1e4f84724c723c7afc9ddbe89b?at=master

Comments

  • JeffersonHenrique
    Options
    Hi @Prodigga, you noticed right, we disabled it because in the early implementations we find a few issues with rollback, we decide to make other things stable before work on turn it back on and test it, so thanks for the report about it.