Help With Animation

Godot Version

4.2.1.stable

Question

I need help with adding animations to my topdown RPG. I thought that this would work but it doesn’t. PLease show me correct code.


extends CharacterBody2D

@onready var animations = $AnimationPlayer
@export var speed: int = 50

func handleInput():
	var directionMove = Input.get_vector("ui_left", "ui_right", "ui_up","ui_down")
	velocity = directionMove*speed
	
func updateAnimations():
	var directionAnim = "Down"
	if velocity.x < 0: directionAnim = "Left"
	elif velocity.x > 0: directionAnim = "Right"
	elif velocity.y < 0: directionAnim = "Up"
	
	animations.play("walk" + directionAnim)
	
func _physics_process(delta):
	handleInput()
	move_and_slide()

Where you call updateAninations? Because i don’t see you call it anywhere

Thank you. I’ll try. :grinning: :slightly_smiling_face: