Confused as to why he only jumps while walking?

And when he runs he gets stuck in the air and can walk in the air? Here’s my frankenscript for jumping I’ve only solved one problem to encounter another and I could really use some help. Not sure why this is so complicated.

  Animator anim;
    public float jumpSpeed = 8.0F;
    
    private Vector3 moveDirection = Vector3.zero;
   
    private CharacterController _charController;
    public float speed = 6.0f;
    public float gravity = 10f;

    private float verticalVelocity;
    private float jumpForce = 5.0f;
    private float gravityJump = 14.0f;

    void Start()
    {
        _charController = GetComponent<CharacterController>();
        anim = GetComponent<Animator>();
    }

    void Update()
    {          
    
        if (_charController.isGrounded)
        {
            verticalVelocity = -gravityJump * Time.deltaTime;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                anim.SetTrigger("Jump");
                float deltaX = Input.GetAxis("Horizontal") * speed;
                float deltaZ = Input.GetAxis("Vertical") * speed;
                Vector3 movement = new Vector3(deltaX, 0, deltaZ);
                movement = Vector3.ClampMagnitude(movement, speed);

                movement.y = gravity;

                movement *= Time.deltaTime;
                movement = transform.TransformDirection(movement);
                _charController.Move(movement);
                verticalVelocity = jumpForce;
            }
        }
        else
        {
            verticalVelocity -= gravityJump * Time.deltaTime;
        }

        Vector3 jumpVector = new Vector3(0, verticalVelocity, 0);
        _charController.Move(jumpVector * Time.deltaTime);

    }
}

first of all, this is most likely not a scripting problem, but a problem with your animator state machine.
you probably (i’m guessing, since you haven’t provided enough info) have transition to jump animation only from walking animation, so when you’re idle, …there’s no transition to jump.

also, getting stuck in the air is similar problem, your transition from jump animation back to walking happens mid-jump-animation or something like that.