Need Help With Animation Code

Godot Version

`V4.3

Question

So I’ve been following a bunch of tutorials on youtube about creating movement and animating sprites and all the great gamedev things, and I finally found a tutorial that was pretty simple to follow and easy to understand (linked below if anybody wants it). This tutorial gave me the following lines of code, alongside an animation player, animation tree, and sprite2d all under a CharacterBody2D node.

extends CharacterBody2D

@export var SPEED = 10000
@onready var anim_tree = get_node(“AnimationTree”)

func _physics_process(delta):
var input_vector = Vector2(
Input.get_action_strength(“right”) - Input.get_action_strength(“left”),
Input.get_action_strength(“down”) - Input.get_action_strength(“up”)
)
self.velocity = input_vectordeltaSPEED

if input_vector == Vector2.ZERO:
	anim_tree.get("parameters/playback").travel("idle")
else:
	anim_tree.get("parameters/playback").travel("run")
	anim_tree.set("parameters/idle/BlendSpace2D/blend_position", input_vector)
	anim_tree.set("parameters/run/BlendSpace2D/blend_position", input_vector)
	anim_tree.set("parameters/attack/BlendSpace2D/blend_position", input_vector)



move_and_slide()

My problem is that when I open up the debug window (I think that’s what it’s called) and do the normal inputs to test everything, the only animation that plays is my left facing idle and run (i haven’t created the inputs for attacking yet).

Any and all help is appreciated!

Tutorial I used: https://www.youtube.com/watch?v=km4SGFzpEc0&t=166s

It looks like you’re facing an issue with the movement input affecting only one direction (left), which could be due to a couple of things in your code setup.
Animation Tree Setup: Since you’re using a BlendSpace2D, it’s important to make sure that your blend points (for idle and run) are configured correctly for each direction (up, down, left, right). If the blend points only cover left and idle, the other directions won’t animate properly.You’re setting the blend_position for idle, run, and attack in the same way. Since you’re only dealing with idle and run animations (you haven’t set up attack yet), just set the blend_position for the current animation:
code: if input_vector == Vector2.ZERO:
anim_tree.get(“parameters/playback”).travel(“idle”)
anim_tree.set(“parameters/idle/BlendSpace2D/blend_position”, input_vector)
else:
anim_tree.get(“parameters/playback”).travel(“run”)
anim_tree.set(“parameters/run/BlendSpace2D/blend_position”, input_vector)

Do try this…snippet…code:
extends CharacterBody2D

@export var SPEED = 10000
@onready var anim_tree = get_node(“AnimationTree”)

func _physics_process(delta):
var input_vector = Vector2(
Input.get_action_strength(“right”) - Input.get_action_strength(“left”),
Input.get_action_strength(“down”) - Input.get_action_strength(“up”)
)

self.velocity = input_vector * delta * SPEED

if input_vector == Vector2.ZERO:
    anim_tree.get("parameters/playback").travel("idle")
    anim_tree.set("parameters/idle/BlendSpace2D/blend_position", input_vector)
else:
    anim_tree.get("parameters/playback").travel("run")
    anim_tree.set("parameters/run/BlendSpace2D/blend_position", input_vector)

move_and_slide()

Check Input Actions: Make sure the actions “right”, “left”, “up”, and “down” are correctly set in your Input Map under Project Settings > Input Map.

Well I hope this help do try…