How can I make the game not "speed up" when fps goes up?

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

All my game logic is in _process() which runs every frame. For example breaking a block would take 20 ticks each tick corresponding to a frame. So in theory the block would take 1/3 of a second to break. But if you increase the fps the block breaks faster. And if the fps decreases the game logic runs slower. In Minecraft if the frame rate goes higher or lower the “speed” of the game still stays the same. How do they achieve that?

:bust_in_silhouette: Reply From: denxi

You want your code to be in _physics_process. _process runs as much as it can, either limited by hardware or by v-sync, but _physics_process runs at a fixed rate. You can set this rate in the project settings, but the default is 60.

:bust_in_silhouette: Reply From: jgodfrey

You can continue to use the _process function. The trick is to use the delta argument that’s passed into _process in your movement code.

That value is the elapsed time since the previous frame (so, the time since the last call to _process). As the FPS changes, that value will change also, allowing you to “normalize” your movement code to be consistent regardless of varying frame rates.

Generally, you want to multiply your movement code by delta to normalize it.

See here for more details: