Double Jump Animation Trouble (Animation Cut Off)

Godot Version

4.7

Question

I’ve been having a bit of trouble with programming my double jump. I’m using a modified version of the character controller script from Brackey’s tutorial introducing both a “double jump” and “fall” state. I managed to implement the “fall” animation no problem, but the double jump keeps being cut off either because it’s adding the gravity too soon or the velocity is giving it issues since when I bring the “jump” command it just reads as the “JUMP_VELOCITY” which is self explanatory. Is there a way I can make sure that the double jump animation transitions more clear into the “fall” animation?

BELOW ARE SOME PICTURE EXAMPLES vvvv

QyVy295

(After I edited the code)

dPRFFBU

(Before; since I’ve returned to this version)

I’ll also include the script for reference. Any help will be appreciated, but I also would shrug at just removing the animation since the logic still works just fine by itself.

extends CharacterBody2D

#Movement
const SPEED = 200.0
const JUMP_VELOCITY = -300.0

#Double Jump
var JUMP_COUNT = 0
var MAX_JUMP = 1

#Spawn
var is_spawned:bool=false


# Get the gravity from the project settings to be synced with RigidBody nodes.

var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

@onready var animated_sprite = $AnimatedSprite2D
@onready var ray_cast: RayCast2D = $RayCast2D

func _ready():
	animated_sprite.play("spawn")
	await animated_sprite.animation_finished
	is_spawned=true

func _physics_process(delta):
	if not is_spawned:
		return

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

	# Handle jump.
	if Input.is_action_just_pressed("jump") and JUMP_COUNT < MAX_JUMP:
		velocity.y = JUMP_VELOCITY
		JUMP_COUNT += 1

	# Handles double jump
	if is_on_floor():
		JUMP_COUNT = 0
	
	# Get the input direction and handle the movement/deceleration.
	var direction = Input.get_axis("left", "right")

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

	# Play Animation
	if is_on_floor():
		if direction == 0:
			animated_sprite.play("idle")
		else:
			animated_sprite.play("run")
	else:
		animated_sprite.play("jumping")
		if JUMP_COUNT == MAX_JUMP:
			animated_sprite.play("double jump")
		if velocity.y > 0:
			animated_sprite.play("fall")
		
	# Applies movement
	if direction:
		velocity.x = direction * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)

	move_and_slide()

Boosting this since it only got approved this morning.

put a print at the end there where you are transitioning back to fall and see where it is happening. Or add a break point. My guess is it’s immediately flipping to that any bypassing whatever logic you think should be keeping it in a double jump animation.