Sword animations now sync
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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", "")
|
||||
|
||||
+10
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user