• Godot Help
  • How to animate a directional idle animation for topdown 2d game

Hey all, so i'm a bit new to godot and trying to figure out how to both have a good walk and idle animation, but mainly when a player stops in a certain direction (let's say facing the right) I would like to play an idle animation of facing right. I feel like i've watched a million videos and tried several methods but they either don't work at all or are for an older version and no longer work as well. I'm currently trying a method where the animation tree is utilized but it just won't work when idling, only for walking. Thanks for any suggestions!
`extends CharacterBody2D

@export var speed: int = 80
@onready var animation_tree : AnimationTree = $AnimationTree
var direction : Vector2 = Vector2.ZERO

func _ready():
animation_tree.active = true

func _process(delta):
update_animation_parameters()

func _physics_process(delta):
direction = Input.get_vector("left", "right", "up", "down").normalized()

if direction:
	velocity = direction * speed
else:
	velocity = Vector2.ZERO

move_and_slide()

func update_animation_parameters():
if (velocity == Vector2.ZERO):
animation_tree["parameters/conditions/idle"] = true
animation_tree["parameters/conditions/is_moving"] = false
else:
animation_tree["parameters/conditions/idle"] = false
animation_tree["parameters/conditions/is_moving"] = true

if (direction != Vector2.ZERO):
	animation_tree["parameters/Idle/blend_position"] = direction
	animation_tree["parameters/Walk/blend_position"] = direction`


use Mathf.MoveToward() instead of Vector2.Zero.
velocity.X = Mathf.MoveToward(Velocity.X, 0, Acceleration);
velocity.Y = Mathf.MoveToward(Velocity.Y, 0, Acceleration);

if (Move_Dir != Vector2.Zero)
{
Moving = true;
}
else
{
Moving = false;
}

Than you can just use a switch case for each direction for the player movement and idle sprites.
I also don't use GDScript, but the same api calls are done (just in C# naming conventions)