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?

I think you need two separate things
For detection just use a sphere trigger collider with the range you need as a sensor.
For collision with scenery you use a capsule collider or appropriately shaped colliders.

Instead of trying to effectively achieve a 3D collider around your NPC that takes into account the geometry around it, which sounds like it would be impossible to compute efficiently I suggest this; have a typical trigger or collider and on entry or collision do a ray cast from the NPC to the player to determine if they’re in line of sight.

This way you won’t have to effectively try to produce dynamic 3D objects that has it’s shape dependent on the surrounding geometry. I can’t imagine how to calculate that exactly or continuously.

Oh I found a way to do it, its fine
Im just gonna use a single line cast to the player, and if the linecast isnt intersected and its a certain length, then the player is within the line of sight

If you combine this with an in range sensor / sphere collision trigger then you can reduce your raycasts to only when in range.

I would use an overlap sphere combined with a linecast on the player and do a tag check to confirm you hit the player’s collider.(I assume you want to avoid the AI from being able to detect the player through walls).

You might as well ignore everything that is not the player when doing the overlap sphere, so use a layer mask to make it more efficient(so only cast on layer “player” for example).

You know how you can do an inexpensive sphere cast? Distance check :wink:

if(Vector3.Distance(obj1.transform.position, obj2.transform.position) < distanceThreshold)
{
    //stuff;
}

That’d the best you’ll get for the detection stuff you want. If you want physics based collisions, a best fitting box collider is the way to go!