Why are my jump animations not working

gd 4.5.1

extends CharacterBody2D
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D

@onready var oww: AudioStreamPlayer2D = $oww


@onready var progress_bar: ProgressBar = $"../ui/Panel/ProgressBar"



const SPEED = 150.0
const JUMP_VELOCITY = -330.0
@onready var character_body_2d: CharacterBody2D = $"."
var Heath = 100

func _physics_process(delta: float) -> void:
	
	progress_bar.value = Heath
	if (velocity.x > 1 || velocity.x < -1):
		animated_sprite_2d.animation ="running"
	else: 
			animated_sprite_2d.animation ="default"
	if not is_on_floor():
		velocity += get_gravity() * delta
		animated_sprite_2d.animation ="jumping"
	if Heath <= 0:
		get_tree().change_scene_to_file("res://scenes/main_menu.tscn")
	if Input.is_action_just_pressed("j") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		animated_sprite_2d.animation ="jumping"
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var direction := Input.get_axis("l", "r")
	if direction:
		velocity.x = direction * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	
	var isleft = velocity.x < 0
	animated_sprite_2d.flip_h = isleft 
	move_and_slide()

This is my code if you can see any error I would love the help. I am kind of new.

All other animations work fine but it just ether play walking of idle(default) animations when I jump. Don’t know if this help but I use A, D, and space bar for controls. If you have any tips I would love to here them.

This if/else means one of these animations will always be playing, consider your order of operations

  1. physics process starts
  2. if/else play running or default
  3. play jumping
  4. move_and_slide etc, a frame passes

  1. physics process starts again
  2. if/else interrupts jump animation with running or default
  3. not on floor, will not play jumping
  4. move_and_slide etc, a frame passes
3 Likes

Thank you

working great now just changed the else to if is_on_floor https://static.vecteezy.com/system/resources/previews/024/203/262/large_2x/illustration-of-a-man-jumping-frame-by-frame-stick-figure-free-vector.jpg