Godot Version
4.1.3.stable
Question
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):
apply_gravity()
var input = Vector2.ZERO
input.x = Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”)
if input.x == 0:
apply_friction()
$AnimatedSprite2D.play("idle")
else:
apply_acceleration(input.x)
$AnimatedSprite2D.play("run")
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
else:
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
$AnimatedSprite2D.play("double_jump")
if velocity.y > 0:
velocity.y += additional_fall_gravity
$AnimatedSprite2D.play("fall")
elif velocity.y < 0:
$AnimatedSprite2D.play("jump")
var was_in_air = not is_on_floor()
move_and_slide()
var just_landed = is_on_floor() and was_in_air
if just_landed:
$AnimatedSprite2D.play("run")
$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)