IsGrounded not updating properly

Hi Guys,

I am using controller.isGrounded to check if the player is touching the ground to check if he can jump or not. Most of the times it works, but 10% of the time it doesn’t detect I am off the ground to start the jump animation. Is there another way to do this wich is more reliable?

void Update()
    {

        CharacterController controller = GetComponent<CharacterController>();


        if(controller.isGrounded)
        {
            grounded = true;
        }

        if (!controller.isGrounded)
        {
            grounded = false;
        }

        if (Input.GetKeyDown(KeyCode.Space) && grounded == true)
        {
            print("We are grounded");
            anim.SetBool("Jumping", true);
        }
        else
        {
            anim.SetBool("Jumping", false);
        }

    }

CharacterController controller;

void Awake() {
controller = GetComponent<CharacterController>();
}

void Update()
       {
    
            if (Input.GetKeyDown(KeyCode.Space) && controller.Grounded)
            {
                print("We are grounded");
                anim.SetBool("Jumping", true);
            }
            else
            {
                anim.SetBool("Jumping", false);
            }
    
        }

just thought i’d shorten your code a bit, but what exactly is the outcome of your problem?
just a thought though. you could make your Jumping bool a trigger and call SetTrigger instead of SetBool, which comes more natural to a jump. would also remove the else part of your code.