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!