
Godot Combat System
- 251 installs
- 454 repo stars
- Updated July 28, 2026
- thedivergentai/gd-agentic-skills
Use godot-combat-system for development tasks
About
godot-combat-system: A skill for development. This provides functionality for development workflows.
- godot-combat-system
Godot Combat System by the numbers
- 251 all-time installs (skills.sh)
- +27 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #1,530 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/thedivergentai/gd-agentic-skills --skill godot-combat-systemAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 251 |
|---|---|
| repo stars | ★ 454 |
| Last updated | July 28, 2026 |
| Repository | thedivergentai/gd-agentic-skills ↗ |
What it does
Use godot-combat-system for development tasks
Files
Combat System
Expert guidance for building flexible, component-based combat systems.
NEVER Do
- NEVER use direct damage references (`target.health -= 10`) — This bypasses armor, resistances, and invincibility logic. Always use a
DamageData+HealthComponentpattern for consistent results. - NEVER forget invincibility frames (i-frames) — Without them, multi-hit attacks deal damage every single frame. Always apply a brief invincibility period (0.1–0.5s) after taking a hit.
- NEVER keep hitboxes active permanently — This causes unintended "ghost" damage. Enable and disable hitboxes precisely using
AnimationPlayertracks or code-timed triggers. - NEVER use groups for physics-based hit filtering — Collision layers are evaluated in C++ and are significantly faster. Groups don't restrict physics intersections adequately for high-performance combat.
- NEVER emit damage signals without a DamageData object — A raw number loses critical context like damage type, source, and knockback direction.
- NEVER use try/catch blocks with validate targets — GDScript does not support exceptions. Use
has_method(&"take_damage")or theisoperator for safe type checking. - NEVER hardcode hitstun pauses using OS.delay_msec() — This blocks the entire OS thread and freezes the game. Use
create_tween()orEngine.time_scalefor visual hit-stop effects. - NEVER apply massive impulses to a RigidBody inside _process() — Physics-altering impulses must happen in
_physics_process()or_integrate_forces()to remain deterministic and stable. - NEVER couple UI lifebars directly inside the Player script — Use a
health_changedsignal. This keeps your combat logic clean and independent of UI implementation details. - NEVER leave CollisionShapes active on dead entities — Corpses will block players and towers. Disable them immediately using
set_deferred("disabled", true). - NEVER scale CollisionShapes non-uniformly — Non-uniform scaling breaks the physics engine's collision math. Always scale the internal resource (e.g.,
CircleShape2D.radius) instead. - NEVER use instanced Nodes for base stat data — Nodes carry unnecessary overhead. Use Godot's
Resourceclass for lightweight, efficient, and inspectable stat containers. - NEVER use raw strings for elemental damage types — Strings are slow and error-prone. Use
enumflags (optionally with@export_flags) to manage multi-type damage efficiently. - NEVER use standard strings for state names in high-frequency loops — Use
StringName(&"attacking", &"stunned") to drastically improve dictionary lookups and hash comparison speeds. - NEVER forget to duplicate() a shared Resource stats block — If you don't call
duplicate()when instancing a mob, all enemies of that type will share the same health pool.
---
Available Scripts
MANDATORY: Read the appropriate script before implementing the corresponding pattern.
combat_system_patterns.gd
10 Expert patterns: Safe duck-typing, hitstun tweens, nodeless AoE shape casting, and frame-perfect sync.
hitbox_hurtbox.gd
Component-based hitbox with hit-stop and knockback logic.
---
Damage System
# damage_data.gd
class_name DamageData
extends RefCounted
var amount: float
var source: Node
var damage_type: String = "physical"
var knockback: Vector2 = Vector2.ZERO
var is_critical: bool = false
func _init(dmg: float, src: Node = null) -> void:
amount = dmg
source = srcHurtbox/Hitbox Pattern
# hurtbox.gd
extends Area2D
class_name Hurtbox
signal damage_received(data: DamageData)
@export var health_component: Node
func _ready() -> void:
area_entered.connect(_on_area_entered)
func _on_area_entered(area: Area2D) -> void:
if area is Hitbox:
var damage := area.get_damage()
damage_received.emit(damage)
if health_component:
health_component.take_damage(damage)# hitbox.gd
extends Area2D
class_name Hitbox
@export var damage: float = 10.0
@export var damage_type: String = "physical"
@export var knockback_force: float = 100.0
@export var owner_node: Node
func get_damage() -> DamageData:
var data := DamageData.new(damage, owner_node)
data.damage_type = damage_type
# Calculate knockback direction
if owner_node:
var direction := (global_position - owner_node.global_position).normalized()
data.knockback = direction * knockback_force
return dataHealth Component
# health_component.gd
extends Node
class_name HealthComponent
signal health_changed(old_health: float, new_health: float)
signal died
signal healed(amount: float)
@export var max_health: float = 100.0
@export var current_health: float = 100.0
@export var invincible: bool = false
func take_damage(data: DamageData) -> void:
if invincible:
return
var old_health := current_health
current_health -= data.amount
current_health = clampf(current_health, 0, max_health)
health_changed.emit(old_health, current_health)
if current_health <= 0:
died.emit()
func heal(amount: float) -> void:
var old_health := current_health
current_health += amount
current_health = minf(current_health, max_health)
healed.emit(amount)
health_changed.emit(old_health, current_health)
func is_dead() -> bool:
return current_health <= 0Combat State Machine
# combat_state.gd
extends Node
class_name CombatState
enum State { IDLE, ATTACKING, BLOCKING, DODGING, STUNNED }
var current_state: State = State.IDLE
var can_act: bool = true
func enter_attack_state() -> bool:
if not can_act:
return false
current_state = State.ATTACKING
can_act = false
return true
func enter_block_state() -> void:
current_state = State.BLOCKING
func enter_dodge_state() -> bool:
if not can_act:
return false
current_state = State.DODGING
can_act = false
return true
func exit_state() -> void:
current_state = State.IDLE
can_act = trueCombo System
# combo_system.gd
extends Node
class_name ComboSystem
signal combo_executed(combo_name: String)
@export var combo_window: float = 0.5
var combo_buffer: Array[String] = []
var last_input_time: float = 0.0
func register_input(action: String) -> void:
var current_time := Time.get_ticks_msec() / 1000.0
if current_time - last_input_time > combo_window:
combo_buffer.clear()
combo_buffer.append(action)
last_input_time = current_time
check_combos()
func check_combos() -> void:
# Light → Light → Heavy = Special Attack
if combo_buffer.size() >= 3:
var last_three := combo_buffer.slice(-3)
if last_three == ["light", "light", "heavy"]:
execute_combo("special_attack")
combo_buffer.clear()
func execute_combo(combo_name: String) -> void:
combo_executed.emit(combo_name)Ability System
# ability.gd
class_name Ability
extends Resource
@export var ability_name: String
@export var cooldown: float = 1.0
@export var damage: float = 25.0
@export var range: float = 100.0
@export var animation: String
var is_on_cooldown: bool = false
func can_use() -> bool:
return not is_on_cooldown
func use(caster: Node) -> void:
if not can_use():
return
is_on_cooldown = true
# Execute ability logic
_execute(caster)
# Start cooldown
await caster.get_tree().create_timer(cooldown).timeout
is_on_cooldown = false
func _execute(caster: Node) -> void:
# Override in derived abilities
passDamage Popups
# damage_popup.gd
extends Label
func show_damage(amount: float, is_crit: bool = false) -> void:
text = str(int(amount))
if is_crit:
modulate = Color.RED
scale = Vector2(1.5, 1.5)
var tween := create_tween()
tween.set_parallel(true)
tween.tween_property(self, "position:y", position.y - 50, 1.0)
tween.tween_property(self, "modulate:a", 0.0, 1.0)
tween.finished.connect(queue_free)Critical Hits
func calculate_damage(base_damage: float, crit_chance: float = 0.1) -> DamageData:
var data := DamageData.new(base_damage)
if randf() < crit_chance:
data.is_critical = true
data.amount *= 2.0
return dataBest Practices
1. Separate Concerns - Health ≠ Combat ≠ Movement 2. Use Signals - Decouple systems 3. Area2D for Hitboxes - Built-in collision detection 4. Invincibility Frames - Prevent spam damage
---
Elite Godot 4.x Patterns
1. Combat Logging & Telemetry
Use FileAccess and JSON to record combat events to the user:// directory for balancing analytics.
# combat_logger.gd
class_name CombatLogger extends Node
const LOG_FILE := "user://combat_log.json"
var _session_log: Array[Dictionary] = []
func log_damage_event(source: String, target: String, amount: int) -> void:
var event := { "source": source, "target": target, "damage": amount }
_session_log.append(event)
# Optimization: Batch flushes instead of writing on every event
if _session_log.size() >= 10: _flush_to_disk()
func _flush_to_disk() -> void:
var file := FileAccess.open(LOG_FILE, FileAccess.WRITE)
if file:
file.store_string(JSON.stringify(_session_log))
file.close()2. Authoritative Networked Damage
Clients should never dictate damage. Instead, they request a hit validation from the server via RPC, providing the target's node path and intended damage.
# networked_damage_manager.gd
class_name NetworkedDamageManager extends Node
func request_damage(target: Node, amount: int) -> void:
if multiplayer.has_multiplayer_peer():
rpc_id(1, "server_validate_hit", target.get_path(), amount)
@rpc("any_peer", "call_remote", "reliable")
func server_validate_hit(target_path: NodePath, amount: int) -> void:
var sender_id := multiplayer.get_remote_sender_id()
var target_node := get_node_or_null(target_path)
if is_instance_valid(target_node) and target_node.has_method("take_damage"):
# Elite: Insert manual lag-compensation / distance checks here
target_node.take_damage(amount)
rpc_id(sender_id, "client_confirm_hit", target_path, amount)
@rpc("authority", "call_remote", "reliable")
func client_confirm_hit(target_path: NodePath, amount: int) -> void:
print_rich("[color=green]Hit confirmed by server.[/color]")3. Hitbox Visualizer (In-Game Debugging)
Toggle global collision visibility during live gameplay using SceneTree.debug_collisions_hint.
# hitbox_visualizer.gd
class_name HitboxVisualizer extends Node
func toggle_debug_hitboxes() -> void:
get_tree().debug_collisions_hint = not get_tree().debug_collisions_hint
## Set specific debug colors for different combat volumes
static func set_hitbox_color(shape: CollisionShape3D, is_attack: bool) -> void:
shape.debug_color = Color.RED if is_attack else Color.GREENReference
- Master Skill: godot-master
# combat_system_patterns.gd
extends Node
# 1. Safe Duck-Typing for Damage
# EXPERT NOTE: Safely test if a target can receive damage without needing to know its exact class.
func _on_hitbox_impact(target: Node) -> void:
if target.has_method(&"take_damage"):
target.call(&"take_damage", 50)
# 2. Safe Type Casting
# EXPERT NOTE: Use the 'as' keyword. If the cast fails, it securely returns null instead of crashing.
func _on_area_body_entered(body: Node2D) -> void:
var player := body as CharacterBody2D
if player and player.has_method(&"die"):
player.call(&"die")
# 3. Decoupling UI via Signal Binding
# EXPERT NOTE: Connect specific combat data to the UI using Callables and bound arguments.
signal combat_log_requested(source: String, amount: int)
func setup_combat_listeners(entity: Node) -> void:
# Binds "Sword" and 100 to the signal every time it fires
entity.connect(&"on_hit", _log_damage.bind("Sword", 100))
func _log_damage(_src: String, _amt: int) -> void: pass
# 4. Custom Stat Resources
# EXPERT NOTE: Build data containers explicitly for the Godot Inspector to keep logic clean.
# class_name CombatStats extends Resource
# @export var max_health: int = 100
# @export var defense: int = 5
# 5. Exporting Enum Bit Flags
# EXPERT NOTE: Allow designers to set multiple elemental damage types seamlessly in the Inspector.
@export_flags("Fire", "Ice", "Poison", "Electric") var damage_types: int = 0
# 6. Interruptible Hitstun Tweens
# EXPERT NOTE: Cache tweens to allow consecutive hits to safely override and restart animations.
var _hit_tween: Tween
func apply_hitstun_vfx(target: CanvasItem) -> void:
if _hit_tween: _hit_tween.kill() # Cancel previous if still running
_hit_tween = create_tween()
_hit_tween.tween_property(target, "modulate", Color.RED, 0.1)
_hit_tween.tween_property(target, "modulate", Color.WHITE, 0.1)
# 7. Nodeless AoE Shape Casting
# EXPERT NOTE: Bypass Area nodes for an instantaneous, C++ powered physics overlap check.
func check_explosion_at(pos: Vector3, radius: float) -> Array:
var query := PhysicsShapeQueryParameters3D.new()
var shape := SphereShape3D.new()
shape.radius = radius
query.shape_rid = shape.get_rid()
query.transform = Transform3D.IDENTITY.translated(pos)
# Perform direct space state check
return get_world_3d().direct_space_state.intersect_shape(query)
# 8. Unbinding Native Signal Variables
# EXPERT NOTE: Safely ignore default emitted arguments if the target method requires none.
func connect_attack_button(btn: Button) -> void:
# pressed normally suggests passing 0 args, but unbind(1) is useful if a signal sends data you don't want
btn.pressed.connect(_execute_swing.unbind(1))
func _execute_swing() -> void: pass
# 9. Disabling Hitboxes Safely
# EXPERT NOTE: Defer disabling collisions so the physics engine isn't disrupted mid-step.
func disable_hitbox(collider: CollisionShape2D) -> void:
collider.set_deferred(&"disabled", true)
# 10. Frame-Perfect Animation Syncing
# EXPERT NOTE: Override process modes for strict combat determinism (syncing with physics).
func setup_combat_animator(mixer: AnimationMixer) -> void:
mixer.callback_mode_process = AnimationMixer.ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS
# skills/combat-system/scripts/hitbox_component.gd
extends Area3D
## Hitbox Component Expert Pattern
## Standardized damage delivery system working in tandem with HurtboxComponent.
class_name HitboxComponent
@export var damage := 10.0
@export var knockback_force := 5.0
@export var hit_stun_time := 0.2
@export var attack_element := "Physical" # Or Enum
# Optional: Team filtering (layer/mask is preferred, but this adds logic layer)
@export var team_index := 0
func _ready() -> void:
area_entered.connect(_on_area_entered)
monitorable = true
monitoring = true
func _on_area_entered(area: Area3D) -> void:
if area is HurtboxComponent:
if area.team_index != team_index: # Prevent friendly fire
var attack_data = AttackData.new()
attack_data.damage = damage
attack_data.knockback_force = knockback_force
attack_data.hit_stun_time = hit_stun_time
attack_data.element = attack_element
attack_data.source_position = global_position
attack_data.attacker = owner
area.receive_hit(attack_data)
## EXPERT USAGE:
## 1. Add HitboxComponent to Weapon/Projectile
## 2. Set Collision Layer to 'Hitbox'
## 3. Set Collision Mask to 'Hurtbox'
# skills/combat-system/code/hitbox_hurtbox.gd
extends Area2D
## Hitbox/Hurtbox Expert Pattern
## Component-based combat with Hit-Stop and Knockback support.
class_name Hitbox # Or Hurtbox, defined by usage
@export var damage: float = 10.0
@export var knockback_force: float = 200.0
@export var hit_stop_duration: float = 0.05 # Engine freeze time
func _on_area_entered(hurtbox: Area2D) -> void:
if hurtbox.has_method("take_damage"):
# 1. Calculate Knockback Vector
var source_pos = global_position
var target_pos = hurtbox.global_position
var kb_direction = (target_pos - source_pos).normalized()
# 2. Trigger Hit-Stop (Global Freeze)
_apply_hit_stop()
# 3. Transmit Data
hurtbox.take_damage(damage, kb_direction * knockback_force)
func _apply_hit_stop() -> void:
Engine.time_scale = 0.0
await get_tree().create_timer(hit_stop_duration, true, false, true).timeout
Engine.time_scale = 1.0
## EXPERT NOTE:
## Time-scale manipulation for hit-stop must use a SceneTreeTimer
## with 'ignore_time_scale' set to true, or the timer itself will freeze!