How it works...

We have a patrolling component that requires the navigation agent controller to work as intended. First, we calculate the closest point to the agent and move it to that position. After that, we use the pointDistance value to make the agent aware that it needs to move to the next point in the loop. Finally, we use the modulo operation to get the next patrol point without too much validation and just keep increasing the number of the current point.

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition 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.