Double jump animation does not work

Godot Version



Hi IndieQuantum here,

I need some help with my double jump animation not playing. All of my players animations are in a single AnimatedSprite2D node.

My jump animation (a single frame) works when jumping, but when double jumping (which works) the animation for double jumping (which is 6 frames) does not play. It only plays it for a split second but then gets taken over by the jump animation.

I don’t now how to code this to get it to work, please help!

Here is the script for my player(I apologize for the messy script, beginner here):
extends CharacterBody2D

var jump_force = -160
var jump_release_force = -40
var max_speed = 75
var acceleration = 10
var friction = 10
var gravity = 5
var additional_fall_gravity = 2
var double_jump = 1
var double_jump_count = 1

func _physics_process(_delta):
var input = Vector2.ZERO
input.x = Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”)

if input.x == 0:
	if input.x > 0:
		$AnimatedSprite2D.flip_h = false
	elif input.x < 0:
		$AnimatedSprite2D.flip_h = true

if is_on_floor():
	double_jump = double_jump_count
	if Input.is_action_just_pressed("jump"):
		velocity.y = jump_force
	if Input.is_action_just_released("jump") and velocity.y < jump_release_force:
		velocity.y = jump_release_force
	if Input.is_action_just_pressed("double_jump") and double_jump > 0:
		velocity.y = jump_force
		double_jump -= 1
	if velocity.y > 0:
		velocity.y += additional_fall_gravity
	elif velocity.y < 0:
var was_in_air = not is_on_floor()
var just_landed = is_on_floor() and was_in_air
if just_landed:
	$AnimatedSprite2D.frame = 1

func apply_gravity():
velocity.y += gravity

func apply_friction():
velocity.x = move_toward(velocity.x,0,friction)

func apply_acceleration(amount):
velocity.x = move_toward(velocity.x,max_speed * amount,acceleration)

you can check the value of the double jump variable before playing the jump animation and choose to play the double jump animation if it’s 0

Thank you for the reply. I am sorry but I don’t quite understand.

	elif velocity.y < 0:
                 if double_jump > 0:

Don’t copy and paste this, i typed it in the forum editor so the indentation is all messed up

1 Like

This work now! the only problem is that the double jump animation only plays one frame and that’s it. not the whole animation.

did you indent it properly? it looked fine when i typed it in the editor but the actual post has the indentation all messed up

Probably an issue comming from when you setup the animatioon in the animation editor

yes I indented correctly, i did not copy and paste

in my animatedsprite2d node, I have several animations in it. idle, run, jump, and fall animation works just fine. here is a screen shot:

one reason that the animation only plays the first frame is that it is also playing another animation before playing the double jump animation each frame.

for example you will play the idle or run animation before playing any fall or jump animation so the jump animation will reset to the first frame

you can fix this by putting the animation logic all in one place, and checking if the character is in the air before playing idle/run animation

1 Like

another way I could solve this is to have another animatedsprite2d node with only the double jump animation in it, and then have it play when ever I double jump.

then you would have to hide the other animatedsprite2d node when the player double jumps, it would be the same logic, just more nodes

1 Like

I just used a second animatedsprite2d that only has the double jump animation. I used the logic you provided to play around with the visibility of the two animated sprite nodes. So thank you for all your help!