sleepTick method
Called every timestep to update internal sleep timer and change sleep state if needed. @param time The world time in seconds;
Implementation
void sleepTick(double time){
if (allowSleep) {
final sleepState = this.sleepState;
final speedSquared = velocity.lengthSquared() + angularVelocity.lengthSquared();
final speedLimitSquared = math.pow(sleepSpeedLimit, 2);
if (sleepState == BodySleepStates.awake && speedSquared < speedLimitSquared) {
this.sleepState = BodySleepStates.sleepy; // Sleepy
timeLastSleepy = time;
dispatchEvent(Body.sleepyEvent);
}
else if (sleepState == BodySleepStates.sleepy && speedSquared > speedLimitSquared) {
wakeUp(); // Wake up
}
else if (sleepState == BodySleepStates.sleepy && time - timeLastSleepy > sleepTimeLimit) {
sleep(); // Sleeping
dispatchEvent(Body.sleepEvent);
}
}
}