Skip to content
GodotComponents
← Back to components
A green capsule inside a translucent red cylinder, struck by an orange capsule that has its own translucent red shape around it.

Hurtbox

Type: 3D

An Area3D that receives hits from Hitbox areas and reports them with a signal. The other half of a hitbox / hurtbox setup.

Setup

  1. Save the script as hurtbox.gd.
  2. Add an Area3D to anything that can be hit, attach the script and give it a CollisionShape3D.
  3. Put the Hurtbox on its own Collision Layer, for example layer 3 named hurtbox.
  4. Connect the hit signal to your damage logic.

Code

GDScript
class_name Hurtbox
extends Area3D
## Receives hits from Hitbox areas and reports them with a signal.

signal hit(damage: int)


func take_hit(damage: int) -> void:
	hit.emit(damage)

Usage example

GDScript
# enemy.gd
# Forward every hit straight to a HealthComponent.
@onready var hurtbox: Hurtbox = $Hurtbox
@onready var health: HealthComponent = $HealthComponent


func _ready() -> void:
	hurtbox.hit.connect(health.damage)