Health, hitbox and hurtbox components for Godot 4. A passive hitbox deals the damage, an active hurtbox receives it, and a sword with a quick and a heavy attack gives you something to test them with.
The crosshair in the GIF stands in for your mouse.
Features
HealthComponent: a drop-in node withdamage(),heal(),is_alive(),get_ratio()anddamaged,healedanddiedsignals.HitboxComponent: anArea2Dthat deals damage. It carriesdamage,knockback_forceandis_crit, and never reads overlaps itself.HurtboxComponent: anArea2Dthat receives damage. It detects the hitbox, applies the damage to its siblingHealth, knocks its body back, and plays the hit flash, impact particles and a damage number.- One hit per swing. A swing hits each target once, even when the hitbox
overlaps it for several frames.
reset_hits()starts the next swing. - I-frames with one flag:
hurtbox.invulnerable. The player's dash sets it, so you can dash through damage. - A two-attack sword driven by a small
IDLE -> WINDUP -> ACTIVE -> RECOVERYstate machine. The hitbox is only enabled duringACTIVE. - Impact feel: hit-stop, screen shake, a directional camera kick and a zoom
punch on heavy hits, through one
GameManagerautoload. - Named physics layers in
project.godot, so the layer checkboxes in the Inspector sayplayer_hurtboxandenemy_hitboxinstead of numbers.
Requirements
- Godot 4.7 or later, standard build (GDScript only, no .NET needed).
- Tested on Godot 4.7.2 stable on Windows. Earlier 4.x versions are untested.
- Uses the Mobile renderer, which needs Vulkan, Direct3D 12 or Metal.
Quick Start
- Press F5.
- Move with WASD and aim with the mouse.
- Left click for a quick slash, right click for a heavy attack that winds up first.
- Space to dash.
- Smash the barrels, then walk into the spikes on the left, then dash through them.
Known Limitations
- The hurtbox reacts when a hitbox enters it. Standing still inside a hazard
does not keep hurting you. For damage over time, add a timer that calls
health.damage()while the overlap lasts. - Hit-stop sets
Engine.time_scaleto 0 for a few hundredths of a second, which pauses everything that runs on scaled time, not just the fighters. - No enemies fight back here. The player's hurtbox is tested with the spike trap.
- No sound.
HurtboxComponent.hurtandHealthComponent.diedare the natural places to play one. - Death fades the player out and stops input. There is no game-over screen; the demo restarts with R.
- Tested on Godot 4.7.2 on Windows only.
License
MIT for the code. See LICENSE.
Third-Party Assets
The knight, sword, barrel and spike sprites are from
Tiny Dungeon by Kenney, released under
CC0 1.0. Details in THIRD_PARTY_ASSETS.md, and the pack's
original license is in Assets/Tiles/License.txt.
Learn How It Works
Want to understand how this works instead of just copying it?
CodingQuests teaches you how to build systems like this step by step in Godot, with interactive lessons and real projects.
- 2D Roguelike: Combat Core builds this damage system lesson by lesson: the health component, the hitbox and hurtbox contract, the sword and the dodge. The first 4 lessons are free.
- New to Godot? 2D Roguelike: Top-Down Controller builds the movement and dash this project starts from. Free, 8 lessons.
Source code, integration instructions and issue tracker: https://github.com/CodingQuests/godot-hitbox-hurtbox
Changelog for version 1.0.0
2026-10-17 01:26:50
No changelog provided for this version.