AnimationPlayer/Tree Idle animation sutck

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

Issue

Using AnimationPlayer and AnimationTree with BlendSpace2D to control animation states using those blend position graphs

Question

If the character is Idle (no key is pressed) it should default to it’s “original” position in this case Idle left, which if I tweak the BlendPosition2D I can change which one it defaults back to
In the tutorial Idle animation would “remember” the last key pressed like right
How do I get a similar behavior to it?

Code

extends KinematicBody2D
export (int) var speed = 10

export (int) var move_speed = 200
var velocity = Vector2()

onready var animation_player = $AnimationPlayer
onready var animation_tree = $AnimationTree
onready var animation_state = animation_tree.get("parameters/playback")

func move():
	velocity = Vector2()
    var right = Input.is_action_pressed('ui_right')
	var left = Input.is_action_pressed('ui_left')
	var up = Input.is_action_pressed('ui_up')
    var down = Input.is_action_pressed('ui_down')

    if right:
    	velocity.x += move_speed
    if left:
    	velocity.x -= move_speed
    if up:
	    velocity.y -= move_speed
    if down:
    	velocity.y += move_speed
    velocity = velocity.normalized() * move_speed

func animate():
    animation_tree.set("parameters/Idle/blend_position", velocity)
    animation_tree.set("parameters/Run/blend_position", velocity)

    if velocity != Vector2.ZERO:
    	 animation_state.travel("Run")
    elif velocity == Vector2.ZERO:
    	animation_state.travel("Idle")

func _physics_process(_delta):
    move()
    velocity = move_and_slide(velocity)
    animate()

Pics

Links