Physics sleep

Revision as of 03:18, 14 June 2025 by Osmo (talk | contribs) (Created page (Adapted from Script/Why does my physics object not fall%3F.md page on the old wiki))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

You may have encountered a situation where there is a physics object, and a script suddenly removes the floor it's resting on, yet it doesn't fall down. Usually this happens when an object falls asleep.

Simulating physics requires a lot of computing power, so the physics engine puts objects that haven't been active to sleep. This usually happens after 120 frames (2 seconds) if the object's velocity is low enough. Sleeping objects use up very little resources, and if something happens to them, they'll automatically wake up and react to that.

Solutions

Some actions do not make objects wake up, like instantly removing the floor. So you'll need to manually wake it up by doing something physical to it. For example, Add Force with a 0,0,0 force will wake the object up, yet not actually push it anywhere.

For some games it's best to keep all objects awake all the time. This can be done by subtly changing gravity each frame, which will wake everything up. Gobble does this, because the hole moves without physics, yet all objects need to fall into it all the time. Use this method only when needed, as it'll make all physics objects consume CPU resources all the time.