Check Raycast Interception?


I want to have a game object (A) that fires a Raycast at another game object (B) from origin (A) to origin (B).

I want to actually check if anything external from these Objects intercept the raycast. I’m trying to make a ‘line of sight’ type system, and using the Raycast to check if A can see B, and B can see A, etc…

I’m currently firing a Raycast on Update from A, to B:

RaycastHit hit;
Vector3 fwd = _B.transform.position - transform.position;

if (Physics.Raycast(transform.position, fwd, out hit)) 
	Debug.DrawLine(transform.position, hit.point);

The only problem with this is that both objects A and B (in this case, just B), needs a collider which I do not want to do.

I simply want to fire a raycast from A to B, and if that line is broken (something is in the way - that DOES have a collider), then return true.

Get the distance between the 2 objects and pass it to the raycast. If nothing is hit then you have nothing in the way.