Make it clear when to use _process and _physics_process #4937
Replies: 6 comments 14 replies
-
I have written about
Now, If your display is quicker than the physics frequency, and you only move your objects on We want to have physics work on a rate that is not depended on the hardware, because physics is a feedback system, and errors accumulate. Thus, unless you design your physics code very carefully, you would see different behavior when you run it at faster rate. So we want to control the rate instead of leaving it to the hardware. Thus, if you are going to use Now, the good news: a built-in step interpolation solution
If you are going to interact with physics use A similar argument can be done for making graphical updates in Thus: Use This suggest to move graphical objects in By the way, you can call
I want to point out that I would use
What is vsync From the point of view of the code vsync synchronizes Time variability The timing between frames is variable. A frame might take longer because your code is slow, or because the operating system preempts the process to do something else, or because energy saving mode, etc… And you get the time as a parameter called So we know the frame rates are variable. But with Motion in unstable framerate We usually use speeds to define the motion, and I remind you speed is distance divided by elapsed time. So you multiply that speed by the delta time, and time cancels out and you get how much distance it moved. Except, most of the time you don't have to do that because Now, look, what we are doing is approximating an integration: we are adding small deltas to make up the motion (see Euler integration). If we want to make our computations work regardless of the framerate (e.g. to work on |
Beta Was this translation helpful? Give feedback.
-
If I don't see how smooth movement is achievable by moving objects in At least for me it is not clear what is considered "physics" that could go wrong if only |
Beta Was this translation helpful? Give feedback.
-
The physics interpolation tutorials in 3.5 cover this. The gist is that you should always use physics interpolation if you want the game to remain smooth with varying render framerates (and render framerates that aren't a multiple of the physics FPS in general). |
Beta Was this translation helpful? Give feedback.
-
Which function you use for which kinds of logic depends very strongly on the needs of the genre your game belongs to and what your players will specifically demand in practice. Using Similarly, if a game has expensive game logic and slowdown is not acceptable for the genre (like an FPS), putting that game logic in Godot's documentation should not be in the business of telling developers which things they should use, because it varies so much from game to game, and it's impossible/impractical/not its job for it to enumerate every permutation of game genres and end-user concerns. It should be in the business of telling developers what each thing does, what upsides and downsides it has, and giving some critical examples. You should probably use Importantly, using |
Beta Was this translation helpful? Give feedback.
-
Personally as rule of thumb try to run all my code on Before Godot 3, Another aspect to take in account while developing games, is to keep in mind multiple monitor frame-rates. |
Beta Was this translation helpful? Give feedback.
-
Is there a way for _process() to know the time at which it finished its run - i.e. to get an estimate of frame-onset time (in case a frame was skipped to handle other stuff on the cpu) ? but perhaps this is not so simple because _process() runs as fast as possible between frames and then if there are two buffers, the flip of the back buffer happens during the vbi, but _process() may have finished well before that ? |
Beta Was this translation helpful? Give feedback.
-
At least I am not very sure what things I should do in
_process
and_physics_process
functions. I have read the Godot documentation, watched YouTube tutorials and read reddit threads but it seems that everybody seems to be somewhat confused.I know the basics,
_process
is called for every frame and_physics_process
is called 60 times per second. I also know that if I want an object (player for example) to move smoothly, the object's position must be updated in every frame. That means that_process
should be used for calculating the new position. But for some reason, I have seen many cases where movement is calculated in_physics_process
. So are there some reasons why to use_physics_process
even if it makes the movement jittery?Godot documentation should clearly tell
_process
/_physics_process
_process
/_physics_process
Beta Was this translation helpful? Give feedback.
All reactions