I’ve set up a simple ai that hides from the player through waypoints placed around a map and respective score to each waypoint. The ai moves to the waypoint with the highest score. I would love to factor in how many objects are between the waypoint and the player. Since I’m already using linecasts to check if the player can see the waypoint I’d like to know if there is there a way to get how many objects a linecast passes through? Thanks in advanced.
You could use RaycastAll.
You have the starting point of your cast, you get the directionfrom A to B => B - A
Then you use the magnitude of (B - A) to find the distance of your cast:
Vector3 direction = player.transform.position - enemy.transform.position;
float distance = direction.magnitude;
RaycastHit  hits = Physics.RaycastAll(enemy.transform.position, direction.normalized, distance);
int amountOfHits= hits.Length;