There is a problem with animation playback

Godot Version

4.2.1 stable


Good evening, everyone. there is a problem with animation playback. I have characterbody2d, animatedsprite2d is connected to it. the problem is that when the buttons are pressed, the sprite changes, but the animation does not play. maybe the problem is in the code

extends CharacterBody2D

@export var speed = 200

func get_input():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	velocity = input_direction * speed

func _physics_process(delta):

@onready var _animated_sprite = $AnimatedSprite2D

func _process(_delta):
	if Input.is_action_pressed("right"):"right")
	if Input.is_action_pressed("left"):"left")
	if Input.is_action_pressed("up"):"up")
	if Input.is_action_pressed("down"):"down")

this code mean if you dont press “down” button, it will always stop the animation
you need elif

to fix
you do it like this:

func _process(_delta):
	if Input.is_action_pressed("right"):"right")
	elif Input.is_action_pressed("left"):"left")
	elif Input.is_action_pressed("up"):"up")
	elif Input.is_action_pressed("down"):"down")
1 Like

thanks bro

1 Like