Hitbox Timing

This commit is contained in:
Twirpytherobot
2025-11-29 18:24:36 +00:00
parent fab47fb1e0
commit b606563f4d
3 changed files with 46 additions and 16 deletions
+12 -2
View File
@@ -48,6 +48,7 @@ var is_blocking: bool = false
@export var unarmed_active: float = 0.15 # Hit window duration
var _attack_timer: float = 0.0
var _unarmed_hitbox: HitBox = null
var _is_unarmed_attacking: bool = false # Prevents overlapping unarmed attacks
# Dash system
@export var dash_speed_multiplier: float = 2.0
@@ -430,10 +431,14 @@ func _perform_attack():
if _body and _body.animation_player and _body.animation_player.current_animation.begins_with("Attack"):
return
if _attack_timer > 0:
if _attack_timer > 0 or _is_unarmed_attacking:
return
_attack_timer = attack_cooldown
# Calculate total attack duration and ensure cooldown covers it
var total_duration = unarmed_startup + unarmed_active
var cooldown = max(attack_cooldown, total_duration)
_attack_timer = cooldown
_is_unarmed_attacking = true
# Play attack animation once
if _body:
@@ -650,6 +655,7 @@ func _on_unarmed_hit(target: Node, damage_amount: float, knockback_amount: float
func _activate_unarmed_hitbox():
if not _unarmed_hitbox:
_is_unarmed_attacking = false
return
# STARTUP PHASE - Wait before activating (wind-up animation)
@@ -657,6 +663,7 @@ func _activate_unarmed_hitbox():
await get_tree().create_timer(unarmed_startup).timeout
if not _unarmed_hitbox or not is_instance_valid(_unarmed_hitbox):
_is_unarmed_attacking = false
return
# ACTIVE PHASE - Hitbox on, can deal damage
@@ -668,6 +675,9 @@ func _activate_unarmed_hitbox():
if _unarmed_hitbox and is_instance_valid(_unarmed_hitbox):
_unarmed_hitbox.deactivate()
# Attack complete
_is_unarmed_attacking = false
func _on_weapon_area_entered(area: Area3D):
# Check if the area belongs to a WorldWeapon
var weapon = area.get_parent()