0 votes

Thanks for your attention.
Engine Version: 3.2.1 stable ver.
Background: For AnimationPlayer, I have created 8 animations, 4 directions for Idle, 4 directions for Run.
AnimationPlayer
For AnimationTree, set to Active. I'm using StateMachine with BlendSpace2D, one for Idle, one for Run, and got them two-way connected, starting with Idle, and I've got blend set to that three dot one, and blend_position both set to (0,0).
AnimationTree
AnimationTreeProperty
BlendSpace2D
I think I have checked the basics like if I've got AnimationPlayer set or the AnimationTreeRoot set to AnimationNodeStateMachine, Process_Mode set to physics because I am using physicsprocess(delta) in code.

Expect: Animation transition.

Result: Hit keyboard, sprite moves, but only plays the IdleDown(which has been set to autoplay on load) and RunDown animation(same direction), and jumps between them, like they are being played simultaneously. But even if there is no animation autoplay on load, the problem still stands, it's just that there will only be one animation played(RunDown), so the jumping issue disappears.

Here's the code.

extends KinematicBody2D

const ACCELERATION = 500
const MAX_SPEED = 200
const FRICTION = 500

var velocity = Vector2.ZERO

onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")

func _physics_process(delta):
    var input_vector = Vector2.ZERO
    input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")

    input_vector = input_vector.normalized()
    if input_vector != Vector2.ZERO:
        animationTree.set("/parameters/Idle/blend_position", input_vector)
        animationTree.set("/parameters/Run/blend_position", input_vector)
        animationState.travel("Run")
        velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
    else:
        animationState.travel("Idle")
        velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

    velocity = move_and_slide(velocity)

I have no idea, can somebody help me out?

in Engine by (15 points)
edited by

It looks like every thing is correct in your settings/code. Is it the same behavior when you play the AnimationTree in the editor?

Yes, the same behavior.
It turned out to be the path setting of animationTree in code, I should remove the first "/".
Thanks!

1 Answer

+1 vote
Best answer

Remove the "/" before "parameters" in animationTree.set(...). I mean:

Your code:

animationTree.set("/parameters/Idle/blend_position", input_vector)
animationTree.set("/parameters/Run/blend_position", input_vector)

Correct:

animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
by (171 points)
selected by

Thanks!!!
I got stuck here for like 2 days.

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.