8-Directional Movement Animation Problem

TLDR: Player sprite keeps defaulting to leftward idle animation when not in motion, even though there’s an animation for left, right, up, and down. Walking animations working fine.

I’ve been following along HeartBeast’s Action RPG Tutorial. It’s for 3.2, so some stuff doesn’t directly translate.

Whenever I move my player, the directional movement animations work great, but when not in motion, it defaults to a left-facing idle animation, even though I have an animation tree set up with four different idle animations (left, right, up, and down).

Here’s my code for the movement:

extends CharacterBody2D

const max_speed = 80
const acc = 500
const friction = 500

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

func _physics_process(delta):
var input_vector = velocity
input_vector.x = int(Input.is_action_pressed(“right”)) - int(Input.is_action_pressed(“left”))
input_vector.y = int(Input.is_action_pressed(“down”)) - int(Input.is_action_pressed(“up”))
input_vector = input_vector.normalized()

if input_vector != velocity:
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, acc * delta)

else:
animationState.travel(“Idle”)
velocity = velocity.move_toward(velocity, friction * delta)

move_and_slide()

All points on the blend triangles correlate to the correct animations. Y-Axis on both has been extended by 0.1 on either side, so that the animations favor left-running and right-running during diagonals.

Start → Idle (2D Blendspace) ↔ Run (2D Blendspace)

As a beginner, I’ve been messing with this for hours, and I’m totally lost. I’ve poured through the comments on the YouTube video, searched for similar problems elsewhere, and I just can’t find a solution. Please offer any help if you can.

There’s a video of the problem in this Reddit post I made, if you want to see: https://www.reddit.com/r/godot/comments/18uz35w/strange_8directional_movement_animation/

in the video, it’s said to be

if input_vector != Vector2.ZERO:

same thing here
change the velocity to Vector2.ZERO

1 Like

That fixed it! Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.