Raycast is not working

private void InputSensors()
{
Vector3 theta0 = (transform.forward);
Vector3 theta1 = (transform.forward + transform.right);
Vector3 theta2 = (transform.right);
Vector3 theta1dash = (transform.forward - transform.right);
Vector3 theta2dash = (-transform.right); //-(transform.right);

        Ray r = new Ray(transform.position, theta0);
        RaycastHit hit;

        r.origin = transform.position;
        if (Physics.Raycast(r, out hit))
        {
            theta0Sensor = hit.distance / 20;
            print("0: " + theta0Sensor);
        }

        r.direction = theta1;
        if (Physics.Raycast(r, out hit))
        {
            theta1Sensor = hit.distance / 20;
            print("1: " + theta1Sensor);
        }

        r.direction = theta2;
        if (Physics.Raycast(r, out hit))
        {
            theta2Sensor = hit.distance / 20;
            print("2: " + theta2Sensor);
        }

        r.direction = theta1dash;
        if (Physics.Raycast(r, out hit))
        {
            theta1dashSensor = hit.distance / 20;
            print("1': " + theta1dashSensor);
        }

        r.direction = theta2dash;
        if (Physics.Raycast(r, out hit))
        {
            theta2dashSensor = hit.distance / 20;
            print("2': " + theta2dashSensor);
        }
    }

}

This code is giving compiler error, I am trying to put sensor, because I am building a self driving car as my school project, I am a beginner and I have no idea how to work with ray casts, I watched youtube tutorials but none of them worked. Help please.

Just fix all compiler errors, nothing in particular… although now something’s wrong with it and it’s not even taking scripts that were working earlier.

Vector3 fwd = transform.TransformDirection(Vector3.forward);
Vector3 rgt = transform.TransformDirection(Vector3.right);
Vector3 lft = transform.TransformDirection(-(Vector3.right));
Vector3 rgtfwd = transform.TransformDirection(Vector3.forward + Vector3.right);
Vector3 lftfwd = transform.TransformDirection(Vector3.forward - Vector3.right);
Vector3 rrr = transform.TransformDirection(-(Vector3.forward));
Vector3 rgtrrr = transform.TransformDirection(-(Vector3.forward) + (Vector3.right));
Vector3 lftrrr = transform.TransformDirection(-(Vector3.forward) - (Vector3.right));
RaycastHit hit;
Ray r = new Ray(transform.position, fwd);
r.origin = transform.position;
if (Physics.Raycast(transform.position, fwd, out hit, 10))
{
print("fwd: " + hit.distance);
}
if (Physics.Raycast(transform.position, rgt, out hit, 10))
{
print("rgt: " + hit.distance);
}
if (Physics.Raycast(transform.position, lft, out hit, 10))
{
print("lft: " + hit.distance);
}

        if (Physics.Raycast(transform.position, rgtfwd, out hit, 10))
        {
            print("rgtfwd: " + hit.distance);
        }
        if (Physics.Raycast(transform.position, lftfwd, out hit, 10))
        {
            print("lftfwd: " + hit.distance);
        }
        if (Physics.Raycast(transform.position, rrr, out hit, 10))
        {
            print("rrr: " + hit.distance);
        }

        if (Physics.Raycast(transform.position, rgtrrr, out hit, 10))
        {
            print("rgtrrr: " + hit.distance);
        }
        if (Physics.Raycast(transform.position, lftrrr, out hit, 10))
        {
            print("lftrrr: " + hit.distance);
        }

I don’t know how, but this is working just fine now.