Raycast

So my code gets to this part then just jumps ship.
For some reason or another even when this object is facing another object it’ll never trigger.
Just looking to see if anyone would have some idea as to why this would be.

float sightDistance_ = x;
if (Physics.Raycast(transform.position, transform.forward, out hit, sightDistance_))
{
   Debug.Log(hit.collider.tag);
   Debug.Log("Player Found!");
}

The player which this enemy is facing has a capsule collidor so there is something to collide with, its why I’m really confused about this.

This can fail because:

  1. you are already inside the target capsule collider you are trying to hit
  2. your sightDistance_ variable is too small
  3. your transform.forward isn’t pointing in the direction you think it is (at the target you want to see)
  4. you are somewhere much further away from your target than you realize
  5. the target object is marked as “Ignore Raycast” layer

Well I got it working but I kinda feel like I cheated because I just made a empty on the object which was +1y and +0.25z and shot the line from there then it worked

Actually I found the reason… and its funny yet sad cause it’s really been the reason why I’ve been having issues with my code all day.
My capsule collider was .5 smaller then my character controller.