Damage numbers and knockback
This commit is contained in:
+35
-5
@@ -354,17 +354,17 @@ func _perform_attack():
|
||||
if hit_body != self and hit_body is BaseUnit:
|
||||
var attacker_id = multiplayer.get_unique_id()
|
||||
|
||||
# If we're the server, apply damage directly
|
||||
# If we're the server, apply damage directly (default unarmed knockback)
|
||||
if multiplayer.is_server():
|
||||
_server_apply_damage(hit_body.name, attack_damage, attacker_id)
|
||||
_server_apply_damage(hit_body.name, attack_damage, attacker_id, 5.0, global_position)
|
||||
else:
|
||||
# Otherwise, request server to apply damage
|
||||
rpc_id(1, "_server_apply_damage", hit_body.name, attack_damage, attacker_id)
|
||||
rpc_id(1, "_server_apply_damage", hit_body.name, attack_damage, attacker_id, 5.0, global_position)
|
||||
break # Only hit one target per attack
|
||||
|
||||
## Server-side damage application
|
||||
@rpc("any_peer", "reliable")
|
||||
func _server_apply_damage(target_name: String, damage: float, attacker_id: int):
|
||||
func _server_apply_damage(target_name: String, damage: float, attacker_id: int, knockback: float = 0.0, attacker_pos: Vector3 = Vector3.ZERO):
|
||||
if not multiplayer.is_server():
|
||||
return
|
||||
|
||||
@@ -379,7 +379,7 @@ func _server_apply_damage(target_name: String, damage: float, attacker_id: int):
|
||||
|
||||
var target = players_container.get_node(target_name)
|
||||
if target and target is BaseUnit:
|
||||
target.take_damage(damage, attacker_id)
|
||||
target.take_damage(damage, attacker_id, knockback, attacker_pos)
|
||||
|
||||
## Health display and callbacks
|
||||
func _create_health_ui():
|
||||
@@ -520,6 +520,36 @@ func _reset_dash_rotation(rotation_value: float):
|
||||
if _body:
|
||||
_body.rotation.x = rotation_value
|
||||
|
||||
## Override hurt animation from BaseUnit
|
||||
func _play_hurt_animation():
|
||||
if _body and _body.animation_player:
|
||||
# Try to play a hurt/hit animation if it exists
|
||||
if _body.animation_player.has_animation("Hurt"):
|
||||
_body.animation_player.play("Hurt")
|
||||
elif _body.animation_player.has_animation("Hit"):
|
||||
_body.animation_player.play("Hit")
|
||||
elif _body.animation_player.has_animation("TakeDamage"):
|
||||
_body.animation_player.play("TakeDamage")
|
||||
else:
|
||||
# Fallback: briefly flash the character red
|
||||
_flash_hurt()
|
||||
|
||||
## Flash effect when no hurt animation exists
|
||||
func _flash_hurt():
|
||||
if not _body:
|
||||
return
|
||||
|
||||
# Store original modulate
|
||||
var original_modulate = _body.modulate
|
||||
|
||||
# Flash red
|
||||
_body.modulate = Color(1.5, 0.5, 0.5, 1.0)
|
||||
|
||||
# Return to normal after a brief moment
|
||||
await get_tree().create_timer(0.15).timeout
|
||||
if _body:
|
||||
_body.modulate = original_modulate
|
||||
|
||||
## Weapon System
|
||||
func _setup_weapon_pickup_area():
|
||||
# Create an Area3D to detect nearby weapons
|
||||
|
||||
Reference in New Issue
Block a user