Raycast Modifier: Thick Raycast Problem (with solution)

In RaycastModifier.ValidateLine, you use Physics.SphereCast for thick raycasts. But for some reason, Unity’s sphere casts ignore any collider that the sphere starts inside. This means that if you are right up against a wall with cast radius == agent radius, the sphere cast starts inside the wall and ignores that whole collider (on a box collider at least, I don’t know about other types), leading it to give you a path through the wall.

To fix this, I added the following line before the sphere cast:

if (Physics.CheckSphere(v1 + raycastOffset, thickRaycastRadius, mask)) return false;

Also, I remember reading somewhere that ray and sphere casts are more efficient if you use the overloads without a RaycastHit parameter.

I just realised that each sphere cast will actually cover its end point properly, so the check sphere is only necessary at the very start of the path. So instead of the above code, I added the following to Apply:

...int i = 0;
if (nodes.Count < 3) break;
if (Physics.CheckSphere(nodes[0] + raycastOffset, thickRaycastRadius, mask))
    i = 1;
while (i < nodes.Count - 2)...

I also noticed that the while loop is starting and stopping a stopwatch, but not actually doing anything with it.