For some reason the animation of the sword is not working. I dont know why, i tought that maybe was because of conflict between animations, but now i really dont know the cause.
Im using animation libraries to organize different animations in a single animationPlayer. And Im using a state machine too, but i think its a problem on my attack state. So here it is
class_name Attack
@onready var animations = $"../../AnimationPlayer"
@export var player : CharacterBody2D
@onready var weapon = $"../../Weapons"
func _on_enter() -> void:
var attack_direction = player.player_direction
if attack_direction == Vector2.ZERO:
attack_direction = player.last_direction
# Normaliza direções diagonais para os eixos principais
if abs(attack_direction.x) > abs(attack_direction.y):
attack_direction.y = 0 # Mantém apenas o eixo horizontal
attack_direction.x = sign(attack_direction.x) # Converte para -1 ou 1
else:
attack_direction.x = 0 # Mantém apenas o eixo vertical
attack_direction.y = sign(attack_direction.y) # Converte para -1 ou 1
print("Direção normalizada:", attack_direction)
if attack_direction == Vector2.UP:
animations.play("Sword/attackUp")
elif attack_direction == Vector2.DOWN:
animations.play("Sword/attackDown")
elif attack_direction == Vector2.LEFT:
animations.play("Sword/attackLeft")
elif attack_direction == Vector2.RIGHT:
animations.play("Sword/attackRight")
print("Animação iniciada:", animations.current_animation)
func _on_animation_finished(anim_name):
print("Animação terminada:", anim_name)
Transitioned.emit("idle")
func _on_exit() -> void:
animations.stop() ```
On the print is how i organized the nodes on the player node