Realistic field of view effect

Now that we have the vision detection working, we can move on to the next step and add a realistic field of view effect. This will allow the character to have peripheral vision, making what is seen on the sides less detailed and what is seen in the front more detailed. It is a simulation of our real human vision, where we tend to focus more on what is in front of us and if we need to check something that is on the sides, we need to turn into that direction in order to have a better look.

Let's start by opening our FieldOfView script. Then we add a new float variable called meshResolution:

public float viewRadius; [Range(0,360)]public float viewAngle; public LayerMask targetMask; public LayerMask obstacleMask; ...

Get Practical Game AI Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.