How to do it...

We will create the function that computes the quality of the waypoint:

  1. Define the function with its parameters:
public static float GetCoverQuality( 
        Vector3 location, 
        int iterations, 
        Vector3 characterSize, 
        float radius, 
        float randomRadius, 
        float deltaAngle) 
{ 
    // next steps 
} 
  1. Initialize the variable for handling the degrees of rotation, possible hits received, and valid visibility:
float theta = 0f; 
int hits = 0; 
int valid = 0;
  1. Start the main loop for the iterations to be computed on this waypoint and return the computed value:
for (int i = 0; i < iterations; i++) 
{ 
    // next steps 
} 
return (float)(hits / valid); 
  1. Create a random position near the waypoint's origin to see whether the waypoint is easily reachable:
Vector3 ...

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.