0 votes


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


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?


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:
    elif velocity == Vector2.ZERO:

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



Godot version 3.4.4
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.