Issue with Jumping and Landing Animations - Animation Handling

Description: Hello, I’m using Unity to implement jumping and landing animations for my character. The jumping animation works correctly, but I’m experiencing a problem with the landing animation.
When the character jumps, the landing animation starts immediately and doesn’t play properly, which is not the desired behavior.
I’m using a raycast to check if the character is on the ground, and when the character is on the ground and the Space key is pressed, I want the jumping animation to play.
However, I need help identifying what’s wrong with the landing animation and how I can resolve it. I would appreciate any suggestions or guidance on finding a solution. Thank you.

that’s my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerScript : MonoBehaviour
    [Header("Player Stats")]
    [SerializeField] PlayerStats playerStats;
    [SerializeField] CharacterController controller;
    [SerializeField] Animator _animator;
    [SerializeField] Transform _camera;
    [Header("Player GamePlay Settings")]
    [Range(0, 0.3f)]
    [SerializeField] float RotateSmoothTime = 0.1f;

    float Vertical;
    float Horizontal;
    bool _IsGrounded;
    private void Update() {
        _IsGrounded = isGrounded();
        if (Input.GetKeyDown(KeyCode.Space) && _IsGrounded) {
             _animator.SetBool("jump", true);
             // Jump function work with animation event
        else if(_IsGrounded && _animator.GetBool("jump")) {
            _animator.SetBool("jump", false);
    void AnimationValues() {
        _animator.SetFloat("vertical", Mathf.Abs(Vertical));
        _animator.SetFloat("horizontal", Mathf.Abs(Horizontal));
    private void FixedUpdate() {
    void GetInput() {
        Vertical = Input.GetAxisRaw("Vertical");
        Horizontal = Input.GetAxisRaw("Horizontal");
    void MovePlayer() {
        Vector3 moveDirection = CalculateMoveDirection(); // Calculate the camera direction
        controller.Move(moveDirection * playerStats.Movementspeed * Time.deltaTime); // Move the player
        if (moveDirection.magnitude > 0) { // If the player is moving
            transform.rotation =Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(moveDirection), RotateSmoothTime); // Rotate the player to the direction he is moving
    Vector3 VerticalVelocity =;
    void Jump() {
        VerticalVelocity.y = playerStats.JumpForce;
    void Gravity() {
        VerticalVelocity.y += Physics.gravity.y * Time.deltaTime * 2;
        controller.Move(VerticalVelocity * Time.deltaTime);
    Vector3 CalculateMoveDirection() {
        Vector3 moveDirection =;
        moveDirection += _camera.forward * Vertical;
        moveDirection += _camera.right * Horizontal;
        moveDirection.y = 0;
        return moveDirection;
    bool isGrounded() {
        return Physics.Raycast(transform.position, Vector3.down, 0.1f);

public class PlayerSave {
    public PlayerStats playerStats;
    public PlayerSave(PlayerStats _playerStats) {
        playerStats = _playerStats;
public class PlayerStats {
    public int health;
    public int maxHealth;
    public float Movementspeed;
    public float JumpForce;

    public PlayerStats(int _health, int _maxHealth, float _movementSpeed, float _jumpForce) {
        health = _health;
        maxHealth = _maxHealth;
        Movementspeed = _movementSpeed;
        JumpForce = _jumpForce;