Physics engine freeze

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By marhov

I’m experience a freeze in the godot physics engine (both bullet and GodotPhysics). I made a very simple example to show the issue:

just clone the repo and run the “Destination” scene. Use keyboard arrows up and down to move. The issue can be reproduced by first press forward and then backward. Then wait for a couple of seconds and the picture will freeze. The freeze happens when the rigid body is moving very slow or not at all and is very easy to reproduce.

Godot versions: 3.1, 3.2 and 3.4 tested and all with same behavior

:bust_in_silhouette: Reply From: omggomb

Either set sleeping to false in the input events or use _physics_process instead of _integrate_forces to add the force. You could also set can_sleep for your Player to false. Whatever makes most sense for your game.

This is because, when not moving for a while, RigidBodies are sleeping. If a body is sleeping, _integrate_forces won’t be called. You can verify this by looking at the remote scene tree and watch the sleeping property change from false to true once the player stops. In fact, if you wait long enough before pressing up or down, it won’t even move on the first key press. This is intended behavior and helps with performance.