AI Line of Site

I’m hoping you can assist me with how implementing The Swindle style line of site might be developed both conceptually and actually implemented within Unity. The game I’m developing is 2D.

The first challenge is creating a visible field of view for the enemy AI that the player can see. The trick is that this field of view needs to act almost like a movable light source in that it needs to be blocked (partially and/or in total) by walls and other collision objects.

The second challenge is implementing collision detection. The player can hide behind walls and crouch behind objects. So I can’t use a single raycast for detection but instead need a raycast that projects out in an arc shape from a singular point. If a line can be drawn between the AI and the player without collision, anywhere in the field of view arc, then the player needs to be detected.

This seems to be what you’re looking for. The video description also contains a link to the source code.

This is exactly what I was looking for thank you so much!

1 Like