So I was trying to write a code for double jump in godot, which I managed to do, but for some reason, when I jump it only plays the first frame of the animation
if is_on_floor():
if on_ground == false:
on_ground = true
jump_count = 0
else:
if on_ground == true:
on_ground = false
jump_count = 1
if velocity.y < 0:
$Sprite.play("jump")
else:
$Sprite.play("fall")
Here is the whole code just in case
const SPEED = 100
const GRAVITY = 8
const JUMPFORCE = -150
const FLOOR = Vector2.UP
var velocity = Vector2(0, 0)
var on_ground = false
var jump_count = 0
var should_change_animation = true
func _physics_process(_delta):
if Input.is_action_pressed("right"):
velocity.x = SPEED
$Sprite.play("run")
$Sprite.flip_h = false
elif Input.is_action_pressed("left"):
velocity.x = -SPEED
$Sprite.play("run")
$Sprite.flip_h = true
else:
$Sprite.play("idle")
if is_on_floor():
if on_ground == false:
on_ground = true
jump_count = 0
else:
if on_ground == true:
on_ground = false
jump_count = 1
if velocity.y < 0:
$Sprite.play("jump")
else:
$Sprite.play("fall")
velocity.y = velocity.y + GRAVITY
if Input.is_action_just_pressed("jump"):
if jump_count < 2:
jump_count += 1
velocity.y = JUMPFORCE
on_ground = false
velocity = move_and_slide(velocity, FLOOR)
velocity.x = lerp(velocity.x, 0, 0.1)
Is there a way to fix this?