0 votes

I was making a bullet hell and noticed that when the game lagged it would mess up the pattern of bullets. Before it lagged I could just stay still and not get hit. But after it lagged the bullets would hit me. I think this was because I set the bullets to shoot out in a certain direction based on the amount of time that has passed, and when lag is introduced some how it messes with that timing. How do I fix this?

Godot version 3.5
in Engine by (56 points)

Are you using physics_process or process. If you are using process function that may likely be the problem.

You could use a static delta, forcing it to 1/60 every _physics_process call in your entire project. That way even if there is lag between frames, your game will behave identically time you run it if you provide it with identical input

Thank you for commenting.
What do you mean a static delta, how would this look in code?

So apparently this worked, thank you for the help.
I put this in a auto-loaded node.

extends Node

static func static_delta():
    return 1.0/60.0

I would like to know why there was a problem with using physics_process with the regular delta.

I tried something else which was changing the Timer node Process Mode to physics rather than idle.

The godot engine tries to ahceive 60 frames per second as best it can. This means most of the time delta = 1.0/60.0, but delta actually represents the time between physics updates. That means if your CPU lags, delta might be like 4.0/60.0 instead of 1.0/60.0, meaning that any movement based on the delta will now move 4 times faster the frame of the lag.

This feature is nice for visual smoothness (a bullet traveling 4 pixel /second doesn't matter if the CPU lagged), but it introduce non-deterministic behavior.

Please log in or register to answer this question.

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.