Keep a list of the bodies the current swing has already hurt, clear it when a new swing starts, and put the character holding the blade on it from the start. In our Godot 4.7 test a blade that damaged everything in get_overlapping_bodies() each physics frame hit the enemy 7 times in one 0.3 second swing, and hit the player holding it 18 times. The script below hit the enemy once per swing and the wielder never.
The code
Put this on an Area3D on the blade, with a CollisionShape3D the size of the blade, and set wielder to your character. Call swing() when the attack's active frames start and stop() when they end, for example from a method track in the AnimationPlayer. Connect hit to play your slash spark.
extends Area3D
## A sword or claw hitbox that hurts each enemy once per swing.
## Put it on the blade with a CollisionShape3D. Call swing() when the attack starts
## and stop() when it ends. Enemies need a take_damage(amount) method.
signal hit(body: Node3D) ## play your slash spark here
@export var damage := 25.0
@export var wielder: Node3D ## the character holding the blade, so it never hurts itself
var _swinging := false
var _hit := [] # who this swing has already hurt
func _ready() -> void:
monitoring = true
func swing() -> void:
_hit.clear()
if wielder:
_hit.append(wielder)
_swinging = true
func stop() -> void:
_swinging = false
func _physics_process(_delta: float) -> void:
if not _swinging:
return
for b in get_overlapping_bodies():
if b in _hit or not b.has_method("take_damage"):
continue
_hit.append(b) # once per swing, however many frames the blade stays inside
b.take_damage(damage)
hit.emit(b)
What we measured
A blade 1.2 m long, from 0.3 m to 1.5 m in front of the shoulder, sweeping from 60 degrees right to 60 degrees left in 0.3 seconds. An enemy capsule stood 1.5 m in front, and the wielder's capsule at the shoulder.
- Damage every physics frame from
get_overlapping_bodies(): the enemy was hit 7 times in the first swing and 14 after two. The wielder was hit 18 times, then 36. - The script: the enemy was hit once per swing, 2 times after two swings. The wielder 0 times.
Two runs gave the same numbers.
Why one cut becomes a burst of hits
get_overlapping_bodies() says who is touching the blade right now, and a blade stays inside an enemy for several physics frames while it sweeps through. Damaging on every frame turns one cut into a burst of hits, and the count changes with the swing speed and the physics rate. The list makes it one hit per swing. The blade also starts right next to the wielder's own body, so without the wielder on the list it cuts the player too.
What to change
damage: per hit, and each enemy takes it once per swing.- For a combo, call
swing()again at the start of each attack, so the same enemy can be hit once by every swing. - A wide sweep through a group hits every enemy in its path once.
Ready-made slashes: Japanese VFX for Godot 4 has 37 presets, including a Katana Slash crescent with sparks in White, Crimson and Azure, plus kitsune fox fire, torii portals, ofuda barriers, sakura petals and a shinobi smoke poof.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Japanese VFX for Godot 4 has 37 ready-made Japanese effects, including a Katana Slash crescent with sparks, kitsune fox fire, torii portals, ofuda barriers and sakura petals.
More how-tos for Japanese VFX for Godot 4: Keep attack presses made just before the swing ends
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
- 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