I am new to Godot. So, to learn I coded 2D platformer movement for my player by following this tutorial and I found a problem that my character is not playing Jump and Fall animation when I press jump but other animations are working fine for me.
extends KinematicBody2D
const UP_DIRECTION := Vector2.UP
export var speed := 50
export var gravity := 5000
export var jump_strength := 800.0
var _velocity := Vector2.ZERO
onready var pivot: Node2D = $AnimatedSprite
onready var _start_scale: Vector2 = pivot.scale
export var maximum_jumps := 1
var jumps_made := 0
func _physics_process(delta: float) -> void:
var horizontal_movement = (
Input.get_action_strength("move_forward")
- Input.get_action_strength("move_backward")
)
_velocity.x = horizontal_movement * speed
_velocity.y += gravity * delta
var is_jumping := Input.is_action_just_pressed("jump") and is_on_floor()
var is_moving := not is_zero_approx(_velocity.x)
var is_idling := is_zero_approx(_velocity.x)
var is_falling := _velocity.y > 0.0 and not is_on_floor()
if is_jumping:
jumps_made = 1
_velocity.y = -jump_strength
elif is_idling:
jumps_made = 0
elif is_moving:
jumps_made = 0
_velocity = move_and_slide(_velocity, UP_DIRECTION)
if not is_zero_approx(_velocity.x):
pivot.scale.x = sign(_velocity.x) * _start_scale.x
if is_jumping:
$AnimatedSprite.play("Jump")
if is_falling:
$AnimatedSprite.play("Fall")
if is_idling:
$AnimatedSprite.play("Idle")
if is_moving:
$AnimatedSprite.play("Walk")