How does one ensure that performance does not impact the time that bullets spawn in?

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

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?

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

umma | 2022-08-12 22:48

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

godot_dev_ | 2022-08-12 23:46

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

Godotuser5675 | 2022-08-13 10:26

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.

Godotuser5675 | 2022-08-13 10:33

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

Godotuser5675 | 2022-08-13 11:09

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.

godot_dev_ | 2022-08-14 16:56