Animation keeps pausing on first frame

version 4

why does my animation pause on the first frame for a second and only then play the rest of the animation?

self explanatory. whenever the animation plays it pauses. if i go the the right, jump and turn only then does it actually work. if you can help me id be pretty jolly. i am very bad at coding. here is my code. help.

extends CharacterBody2D
@onready var animated_sprite = $AnimatedSprite2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0



# Movement
func _physics_process(delta):
	# Gravity
	if not is_on_floor():
		velocity += get_gravity() * delta

	# Jump
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY

	# Movement
	var direction := Input.get_axis("left", "right")

	if direction:
		velocity.x = direction * SPEED

		if Input.is_action_pressed("run"):
			velocity.x *= 5
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	move_and_slide()

	# Animations
	if not is_on_floor():
		if velocity.y < 0:
				animated_sprite.play("jump")
		if velocity.x < -350.0:
				animated_sprite.play ("jump run")
			
		else:
			animated_sprite.play("fall")
	elif direction != 0:
		animated_sprite.play("walk")
		if velocity.x > 500:
				animated_sprite.play("run speed 1")
		if velocity.x < -500:
				animated_sprite.play("run speed 1")
			
		
	else:
		animated_sprite.play("idle")

	# Flip
	if direction > 0:
		animated_sprite.flip_h = false
	elif direction < 0:
		animated_sprite.flip_h = true

whenever what animation?


This sounds like a classic issue, one of these if/elif/elses will always run so your animations may be starting for one frame then overridden on the next as a new animation plays

For example you play “walk” every frame but immediately interrupt it with a “run speed 1”, next frame the same thing happens, “walk” interrupts the second frame of “run speed 1” and the animation starts over again.

Try using if/elif/elses so that only one animation is playing on a given frame, for example your “jump” can be interrupted by “jump run”, but if you make it a elif it’s less likely to interrupt the animation

# Animations
if not is_on_floor():
	if velocity.y < 0:
		animated_sprite.play("jump")
	elif velocity.x < -350.0:
		animated_sprite.play ("jump run")
	else:
		animated_sprite.play("fall")

it kind of worked. maybe i did it wrong. now instead of pausing on the first frame, it plays the regular jump and then the run jump (also the run jump is the animation im trying to fix.)