If the meter refills all the time, or the delay only counts from the first hit, it refills in the middle of a combo and the guard never breaks. In our Godot 4.7 test, 6 blocked hits of 20 every 0.6 s, with a refill of 30 per second, only took those meters down to 71 and 41. Restart the delay on every hit: the same combo broke the guard at 2.4 s, as 5 hits of 20 should.
The code
Call take_hit() with the guard damage when a blocked hit lands, and tick(delta) every frame. Connect guard_broken to your stagger and Guard Break effect. The same script works for a shield or stamina bar that should only recover after a pause.
extends Node
## Guard meter that refills only after a pause in the attacks.
## Call take_hit(amount) when a blocked hit lands and tick(delta) every frame.
signal guard_broken
@export var max_guard := 100.0
@export var refill_per_second := 30.0
@export var refill_delay := 1.0 # seconds without a hit before it starts to refill
var guard := 100.0
var _since_hit := 999.0
func take_hit(amount: float) -> void:
_since_hit = 0.0 # every hit restarts the wait, not only the first one
if guard <= 0.0:
return
guard -= amount
if guard <= 0.0:
guard = 0.0
guard_broken.emit()
func tick(delta: float) -> void:
_since_hit += delta
if _since_hit >= refill_delay and guard < max_guard:
guard = minf(guard + refill_per_second * delta, max_guard)
What we measured
6 hits of 20 at 0, 0.6, 1.2, 1.8, 2.4 and 3.0 s, a refill of 30 per second with a 1 second delay, 60 fps for 5 seconds. Two runs with the same numbers.
- Refilling all the time: lowest 71, never broke, refilled for 3.02 s while still being hit.
- Delay counted from the first hit only: lowest 41, never broke, refilled for 2.02 s while still being hit.
- The script: down to 0 and broken at 2.4 s, no refill at all during the combo, and back up to 31 at 5 seconds, after the 1 second pause.
Why it happens
A refill delay is meant to mean: not hit for a while. A delay that starts once and is never restarted only means: hit at least once, a second ago. Restarting it on every hit makes the meter wait for a real pause, so pressure from fast attacks adds up the way it looks on screen.
What to change
refill_delay: how long the attacker has to keep up the pressure.refill_per_secondandmax_guard: how fast it comes back and how many hits it takes.
Only block what comes from the front: block from the front with a dot product.
Ready-made defense effects: Combat Defense VFX for Godot 4 has 29 presets in Stylized and Retro PSX looks, including Parry Spark, Perfect Parry, Block Wood, Block Metal, Block Magic and Guard Break.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Combat Defense VFX for Godot 4 has 29 ready-made defensive combat effects in Stylized and Retro PSX looks, including Guard Break, Parry Spark, Perfect Parry, Block Wood, Block Metal and Block Magic.
More how-tos: Hazards, traps and attacks
- Turn a 2D character left without the flicker
- A line or rectangle attack that hits what the player sees
- A scare that plays once, and only for the player
- An attack that hits even when a frame is slow
- Growing one cloud or aura zone grows all of them
- A parry window that is the same length on every screen
- A pair of portals that sends you through once
- An expanding shockwave that hits each enemy once
- Explosion damage that walls block, on the frame it goes off
- A fire or poison zone that keeps hurting while you stand in it
- A spike trap that hits whoever is already standing on it
- Who is inside an AoE attack circle
- Block only attacks from the front
- A sword hitbox that hits each enemy once per swing
- Slows and roots that overlap
- Blink forward without going into or through walls
- Knockback that the walk code does not cancel
- Random spots spread evenly inside a circle
- Keep a pressure plate down while anything is still on it
- Heal from the damage that actually landed
- Let the shield take what it can and pass the rest of the hit to health
- A saw blade that slides along its path at a steady speed
- Explosion damage that reaches big enemies
- A spinning laser that hits everything it sweeps over