LayerMask, DrawRay and DrawLine acting weird...

Ok, so I am getting some odd results when I use Physics.DrawRay().

I have created a function for detecting collisions with other game objects on Layer 10.

Unfortunately, while the ray passes through the object, it doesn’t record a collision. (Yes I am certain the object has a Mesh Collider on the appropriate layer).

However, if I then use my LayerMask, none of the collisions happen, and it tells me the length must be greater than 0. (I am trying to ignore Layer 0).

In the image below, Red rays indicate no hit, Yellow means the collider is not hitting the appropriate object, and green means it is correct.

Here is a code snippet:

GameObject MakeRayCasters(Vector3[] corners){
		GameObject origin = new GameObject("RayCaster");
		Vector3 average = new Vector3();
		for (int i = 0; i < corners.Length; i++) {
			average += corners*;*
  •  }*
    
  •  average /= corners.Length;*
    
  •  RaycastHit hit;*
    
  •  Vector3 PlanarUp = Vector3.Cross((Vector3.zero - northPoints[1]).normalized,(Vector3.zero - northPoints[0]).normalized);*
    
  •  LayerMask ignoreLayer = new LayerMask();*
    
  •  ignoreLayer.value = 0;*
    
  •  origin.transform.position = average;*
    
  •  origin.transform.localRotation = Quaternion.LookRotation((Vector3.zero - origin.transform.position).normalized,PlanarUp);*
    

_ if (Physics.Raycast(origin.transform.position+(origin.transform.up50),-origin.transform.up50, out hit)) {_

  •  	if (hit.collider.gameObject.layer==10) {*
    
  •  		Debug.Log(hit.collider.gameObject.name);*
    

_ Debug.DrawRay(origin.transform.position+(origin.transform.up50),-origin.transform.up50,Color.green,Mathf.Infinity);_

  •  	} else {*
    
  •  		Debug.Log("INVALID HIT: " + hit.collider.gameObject.name);*
    

_ Debug.DrawRay(origin.transform.position+(origin.transform.up50),-origin.transform.up50,Color.yellow,Mathf.Infinity);_

  •  	}*
    
  •  } else {*
    

_ Debug.DrawRay(origin.transform.position+(origin.transform.up50),-origin.transform.up50,Color.red,Mathf.Infinity);_

  •  	Debug.Log("MISS: " + hit.point);*
    
  •  }*
    
  •  RayCasters.Add(origin);*
    
  •  return origin;*
    
  • }*
    Here is a screenshot:
    [10504-drawrays.jpg|10504]*

I think I figured out my problem, logic error. I am calling the ray as I build each floor. I need to call it after I build ALL floors :frowning: