Hello, I am new to Godot and I have been working on a basic platformer. Everything works so far, except a few animations, get stuck on the first frame when they are meant to be played. The animations doing this are only the animations used while in the air so I feel like that is something to do with it but I am not sure. Here is the code inside my player:
extends KinematicBody2D
onready var animatedSprite = $AnimatedSprite
onready var dash = $Dash
var UP = Vector2(0, -1)
var gravity = 60
var maxFallSpeed = 600
var maxSpeed = 240
var motion = Vector2()
var jumpForce = 1200
var accel = 30
var jumpCount = 0
var dashSpeed = 200
var dashDuration = 0.2
func _physics_process(delta):
#dash
if Input.is_action_just_pressed("dash") && dash.canDash && !dash.isDashing():
dash.startDash(animatedSprite, dashDuration)
accel = dashSpeed if dash.isDashing() else 30
maxSpeed = 2000 if dash.isDashing() else 240
motion.y += gravity
if motion.y > maxFallSpeed:
motion.y = maxFallSpeed
motion.x = clamp(motion.x, -maxSpeed, maxSpeed)
if Input.is_action_pressed("ui_right"):
motion.x += accel
animatedSprite.play("Run")
elif Input.is_action_pressed("ui_left"):
motion.x -= accel
animatedSprite.play("Run")
else:
motion.x = lerp(motion.x,0,0.2)
animatedSprite.play("Idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
motion.y = -jumpForce
jumpCount = 1
print(jumpCount)
jumpCount = 0
else:
if Input.is_action_just_pressed("jump") && jumpCount < 2:
motion.y = -jumpForce
jumpCount = 2
print(jumpCount)
if motion.x > 0:
animatedSprite.flip_h = false
elif motion.x < 0:
animatedSprite.flip_h = true
if !is_on_floor():
if motion.y < 0:
if jumpCount == 2:
animatedSprite.play("DoubleJump")
else:
animatedSprite.play("Jump")
else:
animatedSprite.play("Fall")
motion = move_and_slide(motion, UP)
The last few lines, playing the jump, double jump, and fall animations, do not work as intended as the animations get stuck on the first frame. I can provide anything else if needed, and help would be very appreciated. Thanks.