Why does func _process() work with different speed on several PC's

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

I’ve got a stamina bar, and passive regen for this bar, the speed of restoring is bounded to the process function, and on my PC it work fine, but when I send my project to my other PC and try to launch them there, the speed of regeneration is way too fast, therefore I need to understand, how to make process work same way on all PC’s.
Otherwise, I wanna find an alternative solution to this problem, If i only can use something else that just a process() function.
Thanks in advance.

Maybe this article from the official documentation will shed some light on using the _process() function?

Ertain | 2021-12-28 04:56

:bust_in_silhouette: Reply From: Gluon

What you need to do is use delta. There is a good training resource here Game Programming: Delta Time | Godot Basics Tutorial | Ep 15 | Godot Tutorials

Fundamentally you multiply a given value by delta to provide the final speed. Delta is going to be bound to how fast the PC is working so it will ensure that each PC will work at a reliable rate.

:bust_in_silhouette: Reply From: Midonk

if I may add some complement to the previous answer, delta represent the time difference (time delta) between this frame and the precedent one.

As process execute as fast as possible for the PC (depending on its CPU processing power) the rate of execution between a PC and another (or even on the same computer but in different situations) may vary.

So when you multiply a speed_factor by delta in a _process or _physic_process callback, the speed_factor is now a unit / second

for exemple, position = transform.x * 200 * delta in a 2D game will move the transform forward by 200 pixels per second

Note: _physic_process has a stable delta which initialy is 1 / 60 (to match 60FPS) however, this can be configured in the “Project” menu

Hope you better understand why your code runs differently using delta or not :wink: