Physics Process or Process for 2D Platformer?

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

I have a 2D platformer and in the player script, I’m using the _physics_process function as the main process function. I So far in my _physics_process function, I have global variables that are consistently updated (like the position of player being stored in a global variable at all times) and is used for different enemies in the game. I also put Input that can be taken in (like if the player pressed the “jump” button). Score variables are also updated in the physics process, collisions, move_and_slide() function, etc. When I run my game on another computer of mines, it runs at a choppy frame rate but on my computer it runs fine (mostly because I have a dedicated graphics card and the other computer doesn’t). Will changing the function to a _process function make the game run smoother? Should I do it? Should I only move some of the code into _process and others in _physics_process()?

:bust_in_silhouette: Reply From: hinasis

Hi!
_process(delta) is called every frame as soon as posible, but it’s not regular.
Instead, _physics_process(delta) is constant because it’s called in regular time periods, so checking position, collisions and other physics related things should be running there.
Try to keep other thing separated. For key input, for example, you can overwrite _input(event) method, if you don’t need to check for physics values.

What do you mean by “you can overwrite _input(event) method”? Do you mean that I should move input commands to _input(event) or something else?

rahsut | 2020-08-19 13:12

In other words, where exactly should I put Input?

rahsut | 2020-08-19 13:48