Two buffs at once is where aura code usually breaks. In our Godot 4.7 test: a 10 second fire buff at 0 s, a 3 second speed buff at 2 s, and the fire buff picked up again for 2 seconds at 4 s, so the last buff really ends at 10 s. A timer per pickup that hides the aura turned it off at 5 s. One Timer restarted on every pickup turned it off at 6 s. One end time per buff kept the aura on until 10.00 s.
The code
Add the script as a child of the character, connect aura_changed to show or hide your aura (or start and stop its particles), and call add_buff(name, seconds) on every pickup. The same buff picked up again is extended when the new time is longer, and never cut short.
extends Node
## Keeps an aura on while at least one buff is still running, even when buffs
## overlap or the same buff is picked up again. Connect aura_changed to your effect.
signal aura_changed(on: bool)
var _now := 0.0
var _ends := {} # buff name -> time it runs out
var _on := false
func add_buff(buff_name: String, seconds: float) -> void:
_ends[buff_name] = maxf(_ends.get(buff_name, 0.0), _now + seconds) # again = longer, never shorter
_update()
func _process(delta: float) -> void:
_now += delta
for k in _ends.keys():
if _ends[k] <= _now:
_ends.erase(k)
_update()
func _update() -> void:
var on := not _ends.is_empty()
if on != _on:
_on = on
aura_changed.emit(on)
What we measured
The pickups above at 60 fps for 12 s. Two runs with the same numbers.
- Each pickup's own timer hides the aura when it ends: off at 5.00 s, when the speed buff ended.
- One Timer, restarted with each pickup's time: off at 6.00 s, 2 s after the second fire pickup.
- The script: off at 10.00 s, and aura_changed sent twice, on and off.
Why it happens
Each of those timers only knows its own pickup. Hiding the aura has to ask whether any buff is still running, and a second pickup must not swap a longer time for a shorter one.
What to change
- A different aura per buff: keep the same end times and show the effect of the buff that ends last.
Aura particles around a character: magic aura particles. Timers and pausing: a cooldown that keeps counting while paused.
Auras that follow the animation: Character Aura Kit for Godot 4 emits auras from a rigged character's own skin and follows the animation: power-up, fire, ice, poison, lightning, dissolve.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Character Aura Kit for Godot 4 emits auras from a rigged character's own skin and follows the animation: power-up, fire, ice, poison, lightning, dissolve.
More how-tos for Character Aura Kit for Godot 4: An aura that comes back when the buff comes back
More how-tos: Auras, rings, beams and weather
- Light shaft cards without the bright edge-on line
- Stretch a bolt sprite from the caster to the target
- Space lights, posts or coins evenly along a Path3D
- Stop a big spinning texture from looking grainy when it is drawn small
- God rays without volumetric fog
- Dark horror fog that works in Compatibility
- Magic aura particles that circle a character
- Charge-up particles that fly in to the middle
- Particle ring standing up instead of flat
- 2D particles from a sprite's shape
- A glowing circle on the ground
- A loot beam that never goes flat
- Chain lightning between enemies
- A tower's attack range ring
- Enemy vision cone with a "!" when it spots you
- Rain that follows the camera
- Rain falling through the roof
- Snow particles not falling
- orbit_velocity not working in 3D: use tangential_accel
- Rain falls through the player
- Snow that stays on roofs
- Emit particles along a Path3D
- Ambient particles in many places from one emitter
- Spin a magic circle forever at the same speed
- Space flying swords, shields or orbs evenly around a character for any count
- Text around a circle with even gaps