I cannot get my charaters animations to work and I feel like im going insane lol

Godot Version

extends CharacterBody3D
class_name Player

@onready var animation_tree: AnimationTree = $AnimationTree
@onready var animated_sprite_3d: AnimatedSprite3D = $AnimatedSprite3D

var last_direction = Vector3.BACK

var state_machine : AnimationNodeStateMachinePlayback
const SPEED = 5.0
const JUMP_VELOCITY = 4.5

func _ready() → void:
state_machine = $AnimationTree.get(“parameters/AnimationNodeStateMachine/playback”) as AnimationNodeStateMachinePlayback

func _physics_process(delta: float) → void:

if not is_on_floor():
	velocity += get_gravity() * delta

# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
	last_direction = direction
	velocity.x = direction.x * SPEED
	velocity.z = direction.z * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	velocity.z = move_toward(velocity.z, 0, SPEED)
if velocity.length_squared() > 0 and is_on_floor():
	$AnimationTree.set("parameters/AnimationNodeStateMachine/conditions/walking", true)
	$AnimationTree.set("parameters/AnimationNodeStateMachine/conditions/idle", false)
else:
	$AnimationTree.set("parameters/AnimationNodeStateMachine/conditions/walking", false)
	$AnimationTree.set("parameters/AnimationNodeStateMachine/conditions/idle", true)
move_and_slide()

Question

I cannot get this animation tree to work, i genuinely have no idea what to do anymore. I’m trying to make a 2.5D game where the character is 2D but the world is 3D. I imported all my animations into the AnimationPlayer mapped them to a BlendSpace 2D inside a StateMachine but for my state machine code never works. Ive watched countless tutorials but nothing seems to work. I think it might be because of my movement code, but im not sure. I’m very, VERY new to coding but Ive spent like 25 hours on this issue alone. I genuinely need help lmao, figured Id post something and see.

Before continuing, please read the post below – particularly the 3rd point under Create a good post:

Given that your animation code is directly linked to the configuration of your AnimationPlayer, you have to provide an overview of the AnimationPlayer as well. Anyone reading your post will be unable to determine where the problem is without having access to the full context of the problem.


Once you provide proper and sufficient information, I will be able to help.

I don’t have an answer but I have the same problem. Playing animations by calling AnimationPlayer.Play works but soon as I try using AnimationTree my character is stuck in T pose.
Maybe its a bug… no idea.