Despite everything i’ve read, Engine.time_scale seems to have no impact on timers created with get_tree().create_timer(). Is this a bug? Is there a way to get them in sync?
Example code:
func _physics_process(_delta: float) -> void:
if !enemies_in_range.is_empty() and is_ready_to_fire:
fire()
func fire():
is_ready_to_fire = false
# fire lasers and stuff
get_tree().create_timer(0.25).timeout
is_ready_to_fire = true
func _on_pause_button_pressed() -> void:
Engine.time_scale = 0.0 # everything stops except firing
func _on_speed_2_button_pressed() -> void:
Engine.time_scale = 2 # everything speeds up except firing
As an example, normally 2 green towers can kill 10 creeps. At double speed 7 make it through. At 5x speed the creeps are barely scratched. Fire rate doesn’t track Engine.time_scale at all.
Oh. My. God. i have used await a thousand other places and somehow didn’t notice that it was missing there. And i’ve been looking at this for two days now. i’m going to crawl in a sewer now.
Technically i still have some problems (towers are slightly less effective at higher speeds) but the towers are clearly speeding up so i’ll need to investigate other possibilities…
That would be the difference between a Timer and using create_timer. If a Timer is not set to “Oneshot” it will carry over any elapsed time.
As an example, let’s say your timer is set to 100ms, and your timer has 2ms left. On the next frame (at 16ms per frame) create_timer it will be made anew back to 100ms ignoring the extra 14ms spent, but a Timer will carry over the elapsed time to 86ms.
For repeating timers like this I highly recommend using the nodes.