Raycast check if grounded with 4 wheels

I have a vehicle with 4 wheels. Every wheel has an raycast collider and a wheel script.
I’m want my grounded variable to be false when all wheels are in air.

I googled a bit and found something like this code but it gave me the error: “No appropriate version of ‘UnityEngine.Physics.Raycast’ for the argument list ‘()’ was found.”

function Update () {
    var hit : RaycastHit;
    if (Physics.Raycast (hit)){
        // if not null, do stuff.
    }
    else // If Raycast did not return anything
    {
        object = null;
    }
}

ok try this one. first make an empty game object and position it where your vehicle is, pointing down then use this code. just reference the function when you want to perform the raycast. dont forget to set the raycast object in the inspector.

public GameObject raycastObject;

void CheckForHit(){

RaycastHit objectHit;

Vector3 fwd = raycastObject.transform.TransformDirection(Vector3.forward);

Debug.DrawRay(raycastObject.transform.position, fwd * 50, Color.green);

if (Physics.Raycast(raycastObject.transform.position, fwd, out objectHit, 50)) {

//do something if hit object ie…

if(objectHit.name==“ground”){

Debug.Log(“grounded”); }

}

}

}

this code extends a raycast for 50m so depending on how far you wish it to go you may need to change these figures both on the debug and the actual raycast. I’m afraid this is in c# code so you will have to convert it.