The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

All my game logic is in _process() which runs every frame. For example breaking a block would take 20 ticks each tick corresponding to a frame. So in theory the block would take 1/3 of a second to break. But if you increase the fps the block breaks faster. And if the fps decreases the game logic runs slower. In Minecraft if the frame rate goes higher or lower the "speed" of the game still stays the same. How do they achieve that?

in Engine by (455 points)

2 Answers

+4 votes
Best answer

You can continue to use the _process function. The trick is to use the delta argument that's passed into _process in your movement code.

That value is the elapsed time since the previous frame (so, the time since the last call to _process). As the FPS changes, that value will change also, allowing you to "normalize" your movement code to be consistent regardless of varying frame rates.

Generally, you want to multiply your movement code by delta to normalize it.

See here for more details:

https://docs.godotengine.org/en/3.2/getting_started/step_by_step/scripting_continued.html#processing

by (22,674 points)
selected by
+2 votes

You want your code to be in _physics_process. _process runs as much as it can, either limited by hardware or by v-sync, but _physics_process runs at a fixed rate. You can set this rate in the project settings, but the default is 60.

by (449 points)
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 Frequently asked questions and 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 [email protected] with your username.