My attack animation doesn't work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DeerForMera

So I have three BlendSpace2D (Idle, Walk and Attack) in my AnimationTree. My “Idle” and “Walk” are working but my “Attack” doesn’t work. All the three Animation have been connected with transition and the Attack already have AtEnd switch mode when travel back.

Here is my animation code

extends KinematicBody2D

onready var anim = $AnimationTree
onready var animstate = $AnimationTree.get("parameters/playback")
var vec = Vector2()


func _physics_process(delta):

vec = Vector2()

if Input.is_action_just_pressed("Attack"):
	animstate.travel("Attack")

if vec == Vector2():
	animstate.travel("Idle")
else:
	animstate.travel("Walk")

	anim.set("parameters/Walk/blend_position", vec)
	anim.set("parameters/Idle/blend_position", vec)
	anim.set("parameters/Attack/blend_position", vec)

	move_and_slide(vec * speed)

I’m sure I make some mistake but I dont know where is it

:bust_in_silhouette: Reply From: Picster
if vec == Vector2():

It will always go into the second if block, so the

animstate.travel("Attack")

will always be overwritten by Idle or Walk.

You could test it by adding a return:

if Input.is_action_just_pressed("Attack"):
   animstate.travel("Attack")
   return
:bust_in_silhouette: Reply From: Gluon

You could try changing it too

if Input.is_action_just_pressed(“Attack”):
animstate.travel(“Attack”)
elif vec == Vector2():
animstate.travel(“Idle”)
else:
animstate.travel(“Walk”)