Keep the seconds left in a variable and subtract delta in _process(). A paused scene tree does not run it, and delta follows Engine.time_scale. A cooldown that compares Time.get_ticks_msec() with the moment it is ready keeps counting through a pause: in our Godot 4.7 test a 3-second cooldown had 2 s left after 1 s of play, and 0.00 to 0.11 s left after a 2-second pause. The script still had 1.99 s left.
The code
Add one of these per ability, for example as a child of the player named FireballCooldown. Call use() when the player presses the button: it returns false while the ability is cooling down, so cast only when it returns true. left is the time remaining for a cooldown bar, and ready_again fires when it is done.
extends Node
## An ability cooldown that waits while the game is paused and runs slower in slow motion.
## Call use() when the player casts: it returns false while the ability is still cooling down.
signal ready_again
@export var seconds := 3.0
var left := 0.0
func use() -> bool:
if left > 0.0:
return false
left = seconds
return true
func _process(delta: float) -> void:
if left <= 0.0:
return
left -= delta # a paused tree does not run this, and delta is scaled by Engine.time_scale
if left <= 0.0:
left = 0.0
ready_again.emit()
What we measured
A 3-second cooldown, used at the start. Two runs gave the same results except the clock-based one, which moved by up to 0.13 s between runs.
- After 1 s of play: the clock-based cooldown 2.01 and 2.14 s left. The script 1.99 s.
- Then 2 s paused: the clock-based cooldown 0.00 and 0.11 s left, ready again the moment the game went on. The script 1.99 s, and use() still returned false.
- Used again, then 1 real second in slow motion at
Engine.time_scale0.5: the clock-based cooldown 2.00 s left. The script 2.50 s, half a second of game time.
Why the system clock is the wrong clock
Time.get_ticks_msec() counts real milliseconds since the game started, whatever the game is doing. A pause menu, a dialogue that pauses the tree, or slow motion all keep that clock running, so a player can open the menu and come back with every ability ready. _process() only runs while the node is not paused, and its delta is game time.
What to change
seconds: the cooldown length.left / secondsgives 1 just after a cast and 0 when ready, for a cooldown bar or a dark overlay on the skill icon.
Slow motion on a big hit: hit stop with time_scale.
A whole spell system: Spell Casting Kit for Godot 4 has cast, charge and channel spells with mana and cooldowns, 4 aiming modes, AoE, elements, status effects such as burn, slow, poison and freeze, knockback, a skill bar with a cast bar, and a demo arena with 9 spells. Its caster counts cooldowns with delta the same way.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Spell Casting Kit for Godot 4 is a whole spell system for Godot 4: cast, charge and channel spells with mana, cooldowns, aiming modes, elements and status effects.
More how-tos for Spell Casting Kit for Godot 4: Aim a spell at the mouse on a 3D floor · Make HP and mana regen the same at any frame rate
More how-tos: Game feel
- A swing that settles the same at any frame rate
- Screen shake that returns to center
- 3D camera shake that lands back on center
- Hit stop and slow motion
- Confetti particles with random colors
- Choppy particles: fixed_fps and interpolate
- Play animations in 12 steps a second, at the right speed on any screen
- Keep a smooth follow camera, but jump with the player when they teleport
- Make a harvested crop pop out in an arc
- Shake a rock or tree when hit, without it drifting
- Pickups that fly to the player in the same time at any frame rate
- Keep attack presses made just before the swing ends
- A dash that covers the same distance at any frame rate
- A hold-to-craft bar that takes the same time at any frame rate and finishes once