Animation stuck

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By soundwave

my chareacter stuck in one animation. After run it still display run instead of idle or same thing wit the jump animation.

extends CharacterBody2D


const SPEED = 300.0
const JUMP_VELOCITY = -400.0


var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var anim=get_node("AnimationPlayer")

func _physics_process(delta):

if not is_on_floor():
	velocity.y += gravity * delta


if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY
	anim.play("jump")


var direction = Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
	if velocity.y==0:
		anim.play("run")
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	if velocity.y==0:
		anim.play("idle")
if velocity.y>0:
	anim.play("fall")

move_and_slide()
:bust_in_silhouette: Reply From: Inces

animation is not meant to be played() in process, because play() starts the timed animation sequence from beginning to end. If You put this line in process(), ti will try to start animation every frame, so it will be stuck at frame 0. Use it in separate input function or signals ir setget.