How to delay collision detection

So basically I’m working on a jump script that looks like:

private void Jump()
{
    if (isGrounded)
    {
        isGrounded = false;
        rigidbody.velocity += Vector3.up * JumpSpeed; //JumpSpeed is defined elsewhere
    }
}

And the isGrounded boolean is reset in:

void OnCollisionStay(Collision collisionInfo)
{
    isGrounded = true;
}

The bug I’m running into is that even though my character has jumped, it takes a couple of frames for it to actually leave the ground. As a result, OnCollisionStay() is still setting isGrounded to true, and allowing my character to jump for multiple times.

One way I think would solve this issue is to introduce a delay every time isGrounded is set to true, as per here. Unfortunately that answer was not very detailed. How can I go about adding a delay to OnCollisionStay (), or is there any better ways of solving the issue? Thanks in advance!

An easy way to accomplish what you’re going for would be to create a jumping bool that’s set to true in your jump function while not setting isGrounded to false until actually losing contact with the collider. Something like this should do the trick…

    private void Jump()
    {
        if (!jumping && isGrounded)
        {
            jumping = true;
            rigidbody.velocity += Vector3.up * JumpSpeed; //JumpSpeed is defined elsewhere
        }

    }
    void OnCollisionStay(Collision collisionInfo)
    {
        isGrounded = true;
    }

    void OnCollisionExit(Collision collisionInfo)
    {
        if (jumping)
        {
            jumping = false;
            grounded = false;
        }
    }