Ask the physics space with intersect_shape() instead of spawning an Area3D, then cast one ray from the blast to each target with the target in the ray's exclude list: anything the ray still hits is a wall. In our Godot 4.7 test a 6 m blast that used distance alone hurt all 6 enemies in range, including 2 behind walls. A ray that only checked is_empty() hurt none of them, because the first thing it hit was the enemy's own capsule. A new Area3D found nobody until its second physics frame. The script hit the 4 in the open on the same frame, from 61.1 damage at 2.3 m down to 14.3 at 5.1 m, and left the 2 behind walls at full health.
The code
Save it as blast_damage.gd and call it where the blast lands: const Blast := preload("res://blast_damage.gd"), then Blast.explode(get_world_3d(), global_position, 6.0, 100.0). Targets need a take_damage(amount) method, and the call returns a Dictionary of who was hit and for how much. Put walls and floors on collision layer 1 and enemies on another layer, so wall_mask = 1 only sees walls.
extends RefCounted
## Explosion damage on the frame it goes off: a sphere query finds who is in range,
## one ray per target checks for walls, and damage falls off with distance.
## Keep enemies off wall_mask (for example walls on layer 1, enemies on layer 2) so they do not shield each other.
static func explode(world: World3D, center: Vector3, radius: float, max_damage: float, wall_mask: int = 1, target_mask: int = 0xFFFFFFFF) -> Dictionary:
var space := world.direct_space_state
var sphere := SphereShape3D.new()
sphere.radius = radius
var q := PhysicsShapeQueryParameters3D.new()
q.shape = sphere
q.transform = Transform3D(Basis(), center)
q.collision_mask = target_mask
var hits := {}
for r in space.intersect_shape(q, 256): # the default is 32 results, and floors and walls count
var body = r.collider
if body in hits or not body.has_method("take_damage"):
continue
var point: Vector3 = body.global_position + Vector3.UP * 0.5 # aim at the chest, not the feet
var d := center.distance_to(point)
if d >= radius or not _clear(space, center, point, body, wall_mask):
continue
hits[body] = max_damage * (1.0 - d / radius)
for body in hits:
body.take_damage(hits[body])
return hits
static func _clear(space: PhysicsDirectSpaceState3D, from: Vector3, to: Vector3, body: CollisionObject3D, mask: int) -> bool:
var ray := PhysicsRayQueryParameters3D.create(from, to, mask, [body.get_rid()])
return space.intersect_ray(ray).is_empty() # the target is left out, so only walls block
What we measured
A blast 0.3 m above the floor with a 6 m radius and 100 damage, and 7 enemies: capsules 2 m tall on collision layer 2, with the floor and two walls on layer 1. Distances are to each enemy's chest, 0.5 m above its center. Two runs gave the same numbers.
- Distance only: all 6 enemies within 6 m were hit, including one 3.23 m away behind a wall and one 4.18 m away behind the other wall.
- One ray from the blast to each enemy, counted as a hit when intersect_ray() came back empty: 0 hits. For the 3 enemies in the open the ray hit the enemy itself. For the 2 behind walls it hit the wall, and for the one standing right behind another enemy it hit that enemy.
- A new Area3D with a 6 m sphere, read right after add_child(): 0 enemies. After the next physics frame: still 0. From the second physics frame on: all 6.
- The script, on the same frame: 61.1 damage at 2.33 m, 38.3 at 3.70 m, 30.4 at 4.18 m and 14.3 at 5.14 m. The 2 behind walls and the one 8.09 m away took 0. Their health went from 100 to 38.9, 61.7, 69.6 and 85.7.
- The same call with wall_mask set to every layer: the enemy behind another enemy took 0 instead of 38.3, because the first enemy blocked its ray.
- 40 enemies in a ring 5 m out: intersect_shape() with its default limit returned 32 results, one of them the floor, so 31 enemies. The script asks for up to 256 and hit all 40.
Why it happens
An Area3D's list of overlapping bodies is filled in by the physics step, so an explosion that reads get_overlapping_bodies() right after it is added gets an empty list, and in our test it stayed empty until the second physics frame. A shape query asks the physics space directly and answers on the spot. A ray aimed at an enemy has to cross the enemy's own collision shape to reach that point, so unless the ray is told to skip the enemy, it always hits something.
What to change
- Big enemies that the blast touches but takes no damage from: falloff from the nearest point of the collision shape.
- The aim point: the script aims 0.5 m above each target's origin. If your enemies have their origin at the feet, aim about 1 m up.
- Low cover: one ray to the chest means an enemy with only its head above a low wall takes nothing. Cast a second ray to the head and count the hit if either is clear.
- Damage that should ignore height, like a shockwave on the ground: an AoE circle that checks distance on the floor. The flash and smoke: one burst of flash, sparks and smoke.
The blast you see: Modern Battlefield VFX for Godot 4 has 29 presets, among them Mortar_Impact, Landmine_Blast and Fuel_Depot_Explosion, in Stylized and PSX looks. The one-shots play with play() and flash a real OmniLight3D. A mortar drops its shell first and hits after a short built-in delay, so call explode() when it hits, not when you call play().
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Modern Battlefield VFX for Godot 4 has mortar, landmine and fuel depot blasts to play where explode() deals the damage.
More how-tos for Modern Battlefield VFX for Godot 4: Explosion effect in one burst · 3D debris particles not rotating · 3D camera shake that lands back on center
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
- 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