From 2ec7d56511f3803fb7cbeeab38f18581cdcd50b6 Mon Sep 17 00:00:00 2001 From: Twirpytherobot Date: Fri, 21 Nov 2025 22:59:41 +0000 Subject: [PATCH] Sword animations now sync --- level/resources/weapon_applecorer.tres | 1 + level/scripts/base_weapon.gd | 7 +++++-- level/scripts/lilguy_body.gd | 15 ++++++++++----- level/scripts/player.gd | 12 ++++++++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/level/resources/weapon_applecorer.tres b/level/resources/weapon_applecorer.tres index 05bfeaf..45506bd 100644 --- a/level/resources/weapon_applecorer.tres +++ b/level/resources/weapon_applecorer.tres @@ -10,6 +10,7 @@ description = "yum" damage = 20.0 attack_range = 3.5 attack_cooldown = 0.6 +attack_animation = "Attack_TwoHandSwing" knockback_force = 12.0 mesh_scene = ExtResource("1_1ytxi") weight = 2.0 diff --git a/level/scripts/base_weapon.gd b/level/scripts/base_weapon.gd index 36d9dcc..7bec717 100644 --- a/level/scripts/base_weapon.gd +++ b/level/scripts/base_weapon.gd @@ -48,9 +48,12 @@ func perform_attack() -> bool: if owner_character and owner_character.is_multiplayer_authority(): owner_character._attack_timer = weapon_data.attack_cooldown - # Play attack animation on owner + # Play attack animation on owner (use weapon's animation) if owner_character._body: - owner_character._body.play_attack() + var anim_name = weapon_data.attack_animation if weapon_data.attack_animation else "Attack_OneHand" + owner_character._body.play_attack(anim_name) + # Sync animation to other clients + owner_character._sync_attack_animation.rpc(anim_name) # Delay damage until animation hits (roughly 70% through the animation) # This makes the damage apply when the swing actually connects diff --git a/level/scripts/lilguy_body.gd b/level/scripts/lilguy_body.gd index 2db3893..66978d9 100644 --- a/level/scripts/lilguy_body.gd +++ b/level/scripts/lilguy_body.gd @@ -16,7 +16,7 @@ func animate(_velocity: Vector3) -> void: return # Don't override attack animation if it's playing - if animation_player.is_playing() and animation_player.current_animation == "Attack_OneHand": + if animation_player.is_playing() and animation_player.current_animation.begins_with("Attack"): return # Check if we're dashing @@ -54,9 +54,14 @@ func _play_animation(anim_name: String): animation_player.play(anim_name) # Silently ignore if animation doesn't exist -func play_attack() -> void: +func play_attack(anim_name: String = "Attack_OneHand") -> void: if animation_player: # Play attack animation once (don't loop) - animation_player.play("Attack_OneHand", -1, 1.0) - # Ensure it doesn't loop - animation_player.animation_set_next("Attack_OneHand", "") + if animation_player.has_animation(anim_name): + animation_player.play(anim_name, -1, 1.0) + animation_player.animation_set_next(anim_name, "") + else: + # Fallback to default if animation doesn't exist + push_warning("Animation '%s' not found, using Attack_OneHand" % anim_name) + animation_player.play("Attack_OneHand", -1, 1.0) + animation_player.animation_set_next("Attack_OneHand", "") diff --git a/level/scripts/player.gd b/level/scripts/player.gd index e04f494..fcbdad0 100644 --- a/level/scripts/player.gd +++ b/level/scripts/player.gd @@ -392,7 +392,7 @@ func _perform_attack(): # Fallback to default unarmed attack # Don't attack if already attacking - if _body and _body.animation_player and _body.animation_player.current_animation == "Attack1": + if _body and _body.animation_player and _body.animation_player.current_animation.begins_with("Attack"): return if _attack_timer > 0: @@ -402,7 +402,9 @@ func _perform_attack(): # Play attack animation once if _body: - _body.play_attack() + _body.play_attack("Attack_OneHand") + # Sync animation to other clients + _sync_attack_animation.rpc("Attack_OneHand") # Find nearest enemy in range var space_state = get_world_3d().direct_space_state @@ -524,6 +526,12 @@ func _perform_dash(): # Animation is handled by the Body's animate function (Jump animation plays during dash) +## Sync attack animation to all clients +@rpc("any_peer", "call_remote", "unreliable") +func _sync_attack_animation(anim_name: String): + if _body: + _body.play_attack(anim_name) + ## Override hurt animation from BaseUnit func _play_hurt_animation(): if _body and _body.animation_player: