Please help. i cant figure out how to fix this finction

I have a function that checks is player grounded. But when i change colider height it doesn’t work properly.

void GroundCheck()
{
    float radius = colider.radius * 0.9f;

    float dist = colider.bounds.extents.y - radius;

    if (Physics.SphereCast(colider.transform.position, radius, Vector3.down, out floor, dist)) 
    {
        //some code
        grounded = true;
    }
    else
    {
        grounded = false;
        //some code
    }
}

I tried many diferent variants of colider.bounds.extents.y, but i’m strugling to find any way to get colder height in world space.

You could try using a Vector3 and floats to define the size and distance of the Cast, and view how it will behave in the Scene view using OnDrawGizmos():

using UnityEngine;
using System;

public class YourScriptName : MonoBehaviour
{
    [Header("Ground Detection")]
    [SerializeField] float groundCheckRadius = 0.5f;// 
    [SerializeField] float groundCheckDistance = 1f;// 
    [SerializeField] Vector3 groundCheckPosition = new Vector3(0, -1, 0);//the position where the sphere cast starts

    // you can remove this if its not needed
    [SerializeField] LayerMask GroundLayer;// only these layers will be detected by the SphereCast, just to make sure the cast does not return true for something that is not the floor. set the layers on the inspector window

    RaycastHit floor;
    bool grounded;



    void GroundCheck()
    {
        if (Physics.SphereCast(transform.position + groundCheckPosition, groundCheckRadius, Vector3.down, out floor, groundCheckDistance, GroundLayer))
        {
            //some code
            grounded = true;
        }
        else
        {
            grounded = false;
            //some code
        }
    }
    
    private void OnDrawGizmosSelected() 
    {
        // Line from where the cast starts to where it ends
        Gizmos.DrawLine(transform.position + groundCheckPosition, transform.position + groundCheckPosition + Vector3.down * groundCheckDistance);

        // sphere to show where the cast ends
        Gizmos.DrawWireSphere(transform.position + groundCheckPosition + groundCheckPosition + Vector3.down * groundCheckDistance, groundCheckRadius);


        //In case you want to check if the GroundCheck is working as intended on the editor
        if (Physics.SphereCast(transform.position + groundCheckPosition, groundCheckRadius, Vector3.down, out RaycastHit tempHit, groundCheckDistance, GroundLayer))
        {
            Gizmos.color = Color.green;
            // draws the wireSphere where the hit occurs
            Gizmos.DrawWireSphere(transform.position + groundCheckPosition + groundCheckPosition + Vector3.down * tempHit.distance, groundCheckRadius);
        }
    }
}

Btw this is a short alternative to write it:

grounded = Physics.SphereCast(transform.position + groundCheckPosition, groundCheckRadius, Vector3.down, out floor, groundCheckDistance, GroundLayer);