Line of Sight Collider

So basically, I need to create a line of sight for my AI for my game to see if they can hit the target or not. I currently have a collider that will determine if there is something blocking the AI’s view.

However I would like to have this colldier change it’s size based on the different between the AI’s location and it’s current target. I was going to use Vector3.Distance to achieve this, however I’m not sure I how can use the numbers it provides me to plug into the collider.

Anyone have any suggestions?

raycasts are pretty much designed for this… use physics.overlapshere to detect all the detectable objects “within range” then raycast to them to see if anything is in the way. If you want to limit the field of view you can then check the angle between the raycast and the AI’s forward vector.

Also might be of interest:

1 Like

I would go with linecast over raycast since youre doing los.

1 Like

Thank you that did the trick.

Thank you for your advice and the video helped