Hitbox vs Hurtbox: What Each Does and How to Draw Them
A hitbox deals damage and a hurtbox receives it. How they differ, when each is active, how to lay them out per frame, and setup in Godot, Unity, GameMaker.
A hitbox deals damage. A hurtbox receives it. A hit happens when an attacker's active hitbox overlaps a defender's hurtbox on layers that are set to detect each other. Neither one is the box that keeps the character standing on the floor; that is a third shape, the body collider.
Keeping the three apart is what makes combat feel fair. The body collider stays stable for movement. The hurtbox is sized for forgiveness. The hitbox appears only on the frames where the attack is striking. This post covers what each box does, how to lay them out across an attack animation, and the setup in Godot 4, Unity and GameMaker.
The three boxes
| Box | Does what | Active when | Usual size | Detects |
|---|---|---|---|---|
| Hitbox | Deals damage | Only during an attack's active frames | About the weapon's swept area, a little larger for the player | Hurtboxes of the other side |
| Hurtbox | Receives damage | Whenever the character can be hurt | Slightly smaller than the visible body for the player | Is detected by hitboxes and hazards |
| Body collider | Moves the character, stops at walls and floors | Always | Narrower than the art, bottom at the feet | World geometry |
Fighting games often add a fourth, usually called a pushbox, that keeps two characters from standing inside each other. In most action and platformer games, the body collider does that job.
Sizing each box is its own topic, covered with ratios and a shipped example in how big a 2D hitbox should be.
The names are not universal
Different codebases use these words differently, so check what a tutorial or engine means before you copy it.
In fighting game vocabulary, hitbox means the attacking box and hurtbox means the vulnerable box, as above. But in Celeste's published player code, the field named hitbox is the body collider used against solid geometry (8 x 11 px for the standing player), and hurtbox is a separate, smaller box checked against hazards and other objects that react to the player (8 x 9 px, ending 2 px above the feet). Some engines and tutorials call any collision shape a hitbox.
Pick one vocabulary for your project, name your nodes and objects accordingly (Hitbox, Hurtbox, BodyCollider), and stay consistent.
How a hit resolves
- The attack animation reaches its first active frame and enables the hitbox.
- The physics engine reports an overlap between the hitbox and a hurtbox.
- Your code checks that this hitbox has not already hit this target during this swing.
- The defender's hurtbox owner applies damage, knockback and hit effects.
- The hitbox is disabled when the active frames end.
Step 3 is the one people forget. Overlap events can fire again if a shape is disabled and re-enabled, or if the target leaves and re-enters the area. Keep a small list of targets already hit per attack and clear it when the attack starts.
Laying out boxes across an attack
Every attack has three phases. Only one of them should have a hitbox.
| Phase | Frames (8-frame swing at 12 fps) | Time | Hitbox | Hurtbox |
|---|---|---|---|---|
| Startup (wind-up) | 1 to 3 | 0 to 250 ms | Off | Normal |
| Active | 4 to 5 | 250 to 417 ms | On, covering the blade's arc | Normal, or extended forward with the arm |
| Recovery | 6 to 8 | 417 to 667 ms | Off | Extended forward (the attacker is open to counterattack) |
At 12 frames per second each frame lasts about 83 ms, so two active frames give the hit a window of about 167 ms. If hits feel hard to land, add an active frame before you grow the box. For how many frames each phase needs, see how many frames an animation needs, and for how anticipation and follow-through read, see game animation for non-animators.
Drawing the boxes:
- Place hitboxes relative to the character's origin, not the sprite cell. With a bottom-center pivot, a sword hitbox might sit 40 px in front and 120 px up from the feet. Sprite pivot points explains why the origin belongs at the feet.
- Mirror them with facing. When the character turns left, flip the hitbox's x offset. If the hitbox is a child of the character and you mirror the character with a negative x scale, the child mirrors with it.
- Use rectangles and circles. Polygon hitboxes look precise in the editor but are hard to tune and rarely improve feel.
Debug colors
A common convention is red for hitboxes and green or blue for hurtboxes, but it varies by team and tool. Celeste's debug view, for example, outlines the player's hurtbox in lime green. Whatever you choose, use the same colors in every debug view and every design note.
Collision layers
Layers keep the right boxes talking to each other and nothing else.
| Layer | Contains | Scans (mask) |
|---|---|---|
| World | Floors, walls | (nothing; static) |
| Player body | Player body collider | World |
| Player hurtbox | Player hurtbox | Enemy attacks, hazards |
| Player attacks | Player hitboxes | Enemy hurtboxes |
| Enemy hurtbox | Enemy hurtboxes | Player attacks |
| Enemy attacks | Enemy hitboxes and projectiles | Player hurtbox |
With this layout, enemy attacks cannot hurt other enemies, and player swords never collide with walls.
Setting it up in Godot 4
Use an Area2D with a CollisionShape2D child for each hitbox and hurtbox. Area2D provides detection: it reports when other areas or bodies overlap it.
- Each
CollisionObject2Dhas 32 physics layers.collision_layeris the layers the object is in;collision_maskis the layers it scans. Name them in Project Settings > Layer Names > 2D Physics. monitoringlets an area detect others.monitorablelets others detect it. A hurtbox needsmonitoringon; a hitbox needsmonitorableon.area_enteredfires on the monitoring area when another area enters it.- Toggle a hitbox by disabling its shape. The docs say to change
CollisionShape2D.disabledwithset_deferred.
# hitbox.gd, on an Area2D
extends Area2D
@export var damage := 1
@onready var shape: CollisionShape2D = $CollisionShape2D
func set_active(on: bool) -> void:
shape.set_deferred("disabled", not on)
# hurtbox.gd, on an Area2D
extends Area2D
signal hurt(damage: int)
func _ready() -> void:
area_entered.connect(_on_area_entered)
func _on_area_entered(area: Area2D) -> void:
if "damage" in area:
hurt.emit(area.damage)
Call set_active(true) on the first active frame and set_active(false) after the last, from an AnimationPlayer method track or the sprite's frame_changed signal.
Setting it up in Unity
Use a Collider 2D with Is Trigger enabled for each hitbox and hurtbox, on child objects of the character.
OnTriggerEnter2Dis sent when another object enters a trigger collider attached to the object. Trigger events are only sent if one of the colliders also has a Rigidbody 2D attached, so put a Rigidbody 2D on the character.- Put hitboxes and hurtboxes on separate Layers and set which pairs can interact in the Physics 2D Layer Collision Matrix.
- Enable the hitbox GameObject only during active frames, using Animation Events or by keying its active state in the clip.
// Hurtbox.cs
using UnityEngine;
public class Hurtbox : MonoBehaviour
{
public System.Action<int> OnHurt;
void OnTriggerEnter2D(Collider2D other)
{
if (other.TryGetComponent(out Hitbox hit))
OnHurt?.Invoke(hit.damage);
}
}
Setting it up in GameMaker
GameMaker collisions use each instance's collision mask, so the cleanest pattern is a separate object per box.
- Create
obj_hitboxwith a plain rectangle sprite as its mask. Spawn it in front of the attacker on the first active frame and destroy it after the last. - Give each character a hurtbox, either its own mask (set a dedicated mask sprite with
mask_index) or a childobj_hurtboxthat follows it. - In the hitbox's Step event, call
instance_place_list(x, y, obj_hurtbox, list, false)to get every hurtbox it overlaps, then apply damage to each one not already hit.
// obj_hitbox Step event
var _hits = ds_list_create();
var _n = instance_place_list(x, y, obj_hurtbox, _hits, false);
for (var i = 0; i < _n; i++) {
var _target = _hits[| i];
if (ds_list_find_index(already_hit, _target) == -1) {
ds_list_add(already_hit, _target);
with (_target.owner) hp -= other.damage;
}
}
ds_list_destroy(_hits);
Create already_hit with ds_list_create() in the Create event and destroy it in the Clean Up event.
Common bugs
| Symptom | Cause | Fix |
|---|---|---|
| One swing hits the same enemy several times | No per-attack hit list | Track targets hit and clear on attack start |
| Attacks hit before the swing looks like it connects | Hitbox enabled during startup frames | Enable only on active frames |
| Enemies damage each other | Layers or masks too broad | Enemy attacks scan only the player hurtbox layer |
| Hitbox appears on the wrong side | Offset not mirrored with facing | Mirror the x offset or parent to a flipped node |
| Character takes damage from walls | Body collider on the hurtbox layer | Separate body and hurtbox layers |
Doing this in Makko
In Art Studio, attack animations are generated within a Collection, so wind-up, strike and recovery frames share the character's look across every sheet. The sprite editor's frame resampling lets you adjust frame count before you bake, which is where you decide how many active frames an attack gets.
In Code Studio, you can @-mention the character and its attack animation in the AI code assistant and ask it to add a hitbox that is enabled on specific frames, plus a hurtbox on the right layers. Then turn on the debug view and tune.
FAQ
What is the difference between a hitbox and a hurtbox?
A hitbox is the area of an attack that deals damage. A hurtbox is the area of a character that can receive damage. A hit registers when an active hitbox overlaps an opposing hurtbox.
Is the hurtbox the same as the collision box?
No. The collision box, or body collider, handles movement against floors and walls and should stay stable. The hurtbox is a separate detection area sized for damage, usually a little smaller than the visible body.
When should a hitbox be active?
Only during the attack's active frames, after the wind-up and before the recovery. Enabling it during startup makes hits land before the swing looks like it connects.
How do I make a hitbox in Godot 4?
Add an Area2D with a CollisionShape2D child, put it on an attack layer, and enable its shape with set_deferred("disabled", false) on active frames. The target's hurtbox is another Area2D with monitoring on that scans the attack layer and handles area_entered.