Difference between _process() and _physics_process()

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

Hello! I’ve been using Godot for quite a while, but I have a beginner question still:

I know that _process() is called every frame while _physics_process() is called every physics frame, which is determined by “Physics Fps” property.

But the thing is: I’ve noticed that my character moves more smoothly when I put the movement code inside _process() rather than _physics_process()

Is there any downsides on doing that?

_process() is called as often as the CPU speed allows, whereas _physics_process() is always called at a fixed rate which may not be as often as when _process() is called, which may explain why it’s smoother.

Ideally you want to put any processing that requires the physics values to be correct in the _physics_process() call.

SteveSmith | 2022-10-10 19:38

Thanks for the answer! I will be using _process() for now, as I don’t see any downsides.

Rubin | 2022-10-10 20:40

:bust_in_silhouette: Reply From: stan.wick.52

Your character moves smoothly in _process() because calculations are made at the frame rate the game is playing at.
Where things start to break is when someone is not playing at the frame rate you intended (As a test, limit your FPS in the engine, you’ll see what I mean).
With slower fps, you’d get slower calculations,
With higher fps, you’d get calculations so fast your physics would be liable to break (think GTA SA with uncapped frame limiter).
That’s why you have _physics_process() to help when you need consistent results irrespective of frame rate.
But a problem arises when your physics fps doesn’t match your game fps, you get jitters and stutters, hence the movement does not appear smooth, and increasing the physics FPS doesn’t really solve that issue. To combat that, Physics interpolation was introduced in Godot 3.5. It helps eliminate jitter and stutter

We can use delta parameter to solve these FPS issues in both _process() and _physics_process(), and as far as I’ve seen, I don’t really see an issue with using _process() (since I always multiply physics calculations with delta).

Rubin | 2022-10-11 14:13

Yes, that’s true to an extent. You won’t notice any problems if your frame rate is consistently above the physics frame rate.
Where you’ll notice an issue is at lower frame rates. The _process() function is generally called after physics calculations have taken place, so anything physics related would jitter if the frame rate is low enough and you could experience clipping, unregistered collisions, stuff like that.
Granted, you can alleviate that by increasing the physics fps, but that’s more strain on hardware, and at that point, you may as well have put the code in physics process.
Either way it all boils down to what’s best for your project.

stan.wick.52 | 2022-10-11 17:26

Ohhh I didn’t knew that. I will do some testing with my project. Thanks for the answer!

Rubin | 2022-10-11 20:50