360 degree's of raycasting

I was wondering if there was a way to make a 360 degree’s raycast. This has been answered before, but the problem with Spherecast and overlaysphere (correct me if Im wrong here) or triggers, is that they go through obstacles and walls, which I dont want to do. I essentially want a range around my AI that can be blocked with objects and detects my player. Any help?

The way you would do it is with a check flag:

first produce the sphereCast and then store everything it returns in a generic list.

then go through that list and flag against anything that you don’t want to draw to.

then draw a raycast to the remaining things in the list.
this way you are doing a 360 degree check, ignoring the things you don’t care about (such as the terrain or walls), then trying to draw a raycast to anything else that is not ignored (such as your enemies). I would recommend that you you do all this in a separate function, that way you can call it in your update event and any changes you want to make can be made in the function.

A raycast draws a line from one point to another, where the endpoint is either the destination point or a impact point between its start and end.

So if an object or player is between the start and end point of the ray the ray will impact on it, and the resuliting hit data can be used to see if its a player.
(check the impact data by tag or name or whatever to match the player)
See colliderHit for more info.

When sending rays in all directions you will have to check (iterate trough) eatch impact point.

In general a ray does not go trough a wall/player unless you put the wall on a layer that is ignored by raycast. I think unity fixed this now but in my code I still set trigger volumes to layer 2 as else raycast would hit them.

See a ray as a beam of invisible light.