Keep last frame's radius. A target was reached this frame if its distance is more than the old radius and no more than the new one, and a list of who was already hit stops a second hit. Checking whether a target is inside the ring's band depends on how far the ring moves in one frame. In our Godot 4.7 test a ring growing 12 m/s with a 0.5 m band hit 14 of 60 targets twice at 30 fps and every target 2 to 6 times at 60 and 144 fps. At 25 m/s and 30 fps it moved 0.83 m a frame and jumped past 25 of the 60, even with a hit-once list. The script hit all 60 exactly once at every frame rate and speed.
The code
Save it as shockwave_hits.gd. Make one when the shockwave goes off, var wave = Shockwave.new(global_position, 12.0, 10.0) after const Shockwave := preload("res://shockwave_hits.gd"), then in _physics_process() call wave.step(delta, enemies) and damage what it returns, until wave.finished(). Distance is measured on the ground, so a target above the ring is still reached.
extends RefCounted
## An expanding shockwave that hits each target once, on the frame the ring reaches it,
## however far the ring moves in one frame.
var center := Vector3.ZERO
var speed := 12.0 # meters per second
var max_radius := 10.0
var radius := 0.0
var _hit := {}
func _init(at: Vector3, meters_per_second: float = 12.0, reach: float = 10.0) -> void:
center = at
speed = meters_per_second
max_radius = reach
## Call every physics frame with the targets (Node3D). Returns the ones the ring reached this frame.
func step(delta: float, targets: Array) -> Array:
var before := radius
radius = minf(radius + speed * delta, max_radius)
var reached := []
for t in targets:
if _hit.has(t):
continue
var d := Vector2(t.global_position.x - center.x, t.global_position.z - center.z).length() # distance on the ground
if d <= radius and (d > before or before == 0.0): # the ring passed it this frame
_hit[t] = true
reached.append(t)
return reached
func finished() -> bool:
return radius >= max_radius
What we measured
60 targets from 0.15 m to 9.9 m from the center, a ring growing to 10 m, at 30, 60 and 144 fps with a fixed delta. The band checks hit a target while it was within 0.25 m of the ring. Two runs gave the same numbers.
- Band check every frame, 12 m/s: at 30 fps 46 targets hit once and 14 twice. At 60 fps every target 2 or 3 times. At 144 fps every target more than once, up to 6 times.
- Band check every frame, 25 m/s: at 30 fps 25 of 60 never hit. At 60 fps 1 missed and 12 hit twice. At 144 fps all hit, up to 3 times each.
- Band check with a hit-once list: no more double hits, but at 25 m/s it still missed 25 at 30 fps and 1 at 60 fps.
- The script: all 60 once, every time. The ring was at most one frame's step past a target when it hit: 0.39 m at 12 m/s and 30 fps, 0.08 m at 144 fps, 0.78 m at 25 m/s and 30 fps.
- A target 3 m up in the air at the edge of the ring's reach was still hit once.
Why it happens
A band check asks where the ring is now, and the ring only exists at the frames you see. When it moves less than the band's width in one frame, a target sits inside the band for several frames in a row and is hit each time. When it moves more than the band's width, the band can land on one side of a target and then the other, and the target is never inside it. Checking the range the ring covered since the last frame catches every target exactly once, whatever the frame rate.
What to change
- Damage that falls off with distance: scale it by 1 - distance / max_radius when step() returns the target.
- Walls that should block the wave: cast a ray to each target it returns, as in explosion damage that walls block. A fixed circle that hits once instead of a growing ring: an AoE circle check.
The ring you see: Arcane VFX Vol 1 has Mana_Shockwave in four versions, plain, Crimson, Gold and Small, as one-shots you start with play(), and PDVFX.set_scale() to resize them. Match the script's speed and reach to the size you pick, then start both on the same frame.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Arcane VFX Vol 1 has Mana_Shockwave in plain, Crimson, Gold and Small versions to play() where the script deals the damage.
More how-tos for Arcane VFX Vol 1: Glowing particles in Godot 4 · A spell that keeps flying straight after it leaves the hand
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
- 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
- Refill the guard meter only after the hits stop
- 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