I’m trying to detect if there is something between my camera and my character. Here is my code:
void Update ()
{
myTarget = target.position + new Vector3(0, offsetY, 0);
length = Vector3.Distance(transform.position, myTarget);
//Shoot Raycasts
RaycastHit[] hits;
hits = Physics.RaycastAll(transform.position, myTarget, length);
Debug.DrawLine(transform.position, myTarget, Color.yellow);
Debug.Log("Number of hits: " + hits.Length);
}
Where myTarget is my character (I’m using an offset to point the center of it).
I’m using length for not to detect the floor.
Here is a screenshot of my scene:
Ass you can see, there is something in my raycast trajectory, but it’s not being detected… Any idea?