Trying to have a ball that rolls using addForce to have a raycast to detect if the ground is underneath it.

Hey, guys, I am trying to make a ball that is rolling in a 2d space detect whether it is on the ground or not for making the ball only jump when it is on the ground. I am currently only having trouble figuring out the ground detection.

`
            RaycastHit Hit;
            float Distance;
            Vector2 up = transform.TransformDirection(-Vector2.up) * 10;
            Debug.DrawRay(transform.position, up, Color.green);
            if (Physics.Raycast(transform.position, (up), out Hit))
            {
                Distance = Hit.distance;
                print(" "+ Distance + " " + Hit.collider.gameObject.name + " ");
            }
`

This is currently what I’m using, but the raycast rolls with the ball instead of staying pointed at the ground. Any assistance would be greatly appreciated!

Is your heart set on using a raycast?

Could you not use OnCollisionEnter and OnCollisionExit to control a flag that tells you whether or not you’re touching the ground?