+1 vote

I have a 2D platformer and in the player script, I'm using the physicsprocess function as the main process function. I So far in my physicsprocess 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, moveandslide() 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 _physicsprocess()?

in Engine by (192 points)

1 Answer

+3 votes
Best answer

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.

by (322 points)
selected by

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?

In other words, where exactly should I put Input?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.