Field of View

By Brogan (Programmer)

Giving the enemy sight was a fun task. I fell upon another great tutorial by Sebastian Lague, which taught a basic field of view technique. Sebastian’s video is aimed at 3D, so I only really needed to swap around some Vector3’s for Vector2’s and it was more or less complete.

One addition I did make was an inner radius. This was because I didn’t want the material to start at a single point, but instead circle around the enemy. The bigger the enemy the bigger the inner radius would need to be. The hardest part about doing that was triangulation for the mesh. I tried using an algorithm from Unify Triangulator, which I could get working with a simple shape, but it wasn’t working with the FOV vertices for some reason. I haven’t quite figured out why. In the end I figured out a way to do this, but I think that another approach could improve performance. For now we will work with what we have, as it serves its purpose.

Animated GIF - Find & Share on GIPHY

The next step is to have a loading bar type effect on the enemy FOV, similar to that of Shadow Tactics, where the sightcone gradually fills up the longer the player stands within it. When the sightcone has filled completely the enemy will change to attack mode and actively pursue the player. This might take some shader code, which I am not confident in, but I’m up for the challenge.