My RayCast is passing through my collider, not sure why.

I have two guys that are sphere colliders and several walls that are box colliders. I have a script which I’m trying to use to determine if there is a wall between the guy guys. This is my script and it always returns “Character” as the tag and the DrawRay goes right through the wall. any ideas?

Ray rVisible = new Ray (transform.position,charPosition);
RaycastHit hit;
if(Physics.Raycast (transform.position, charPosition -transform.position , out hit))

{

Debug.Log (hit.collider.tag);
Debug.DrawRay(transform.position, charPosition -transform.position );

}

Why do you construct a Ray if you dont plug it in to your Raycast?

You should specify a distance, but you dont have to. Try something big, just to make sure, though.

Ray rVisible = new Ray (transform.position,charPosition);
RaycastHit hit;
if(Physics.Raycast (rVisible , out hit, rayDistance))

Thats right.

Oddly enough, I was able to solve it by deleting all my cube colliders and recreating them. Thats an annoying solution that often works.

Thanks for your help