Hi all,
I’m trying to perform a Raycast scan around an object with a set granularity (i.e. 100 rays per 360 degrees) and read all of the Rays I generate that do not hit something and those that do into separate Arrays. However, the code I have written comes up with an ‘object not set to reference of an object’ and I can’t see why.
Just for the record, I’d rather use arrays than lists for this since I want this to work as quickly and efficiently as possible, but if lists work I won’t complain!
Any thoughts would be really appreciated!
Cheers,
Popuppirate
public Ray[] free_rays;
public Ray[] hit_rays;
public RaycastHit[] hit_ray_info;
public int granularity;
public float step;
public float safe_distance;
// Use this for initialization
void Start () {
safe_distance = 3f;
granularity = 100;
step = 0;
}
// Update is called once per frame
void Update () {
if (step <= 360f) {
for (int i=0; i<granularity; i++) {
RaycastHit hit;
Vector3 scan = Quaternion.AngleAxis (step, transform.forward) * transform.forward;
Ray ray = new Ray (transform.position, scan);
if (Physics.Raycast (ray, out hit, safe_distance)) {
hit_rays *= ray;*
hit_ray_info = hit;
* } else {*
free_rays = ray; //ERROR HERE
* }*
_ step +=360f / granularity * 1.0f;
* }
}else {
step =0f;
}*_