Getting ready

We need to make some modifications to our AgentBehaviour class:

  1. Add new member values to limit some of the existing ones:
public float maxSpeed; 
public float maxAccel; 
public float maxRotation; 
public float maxAngularAccel;
  1. Add a function called MapToRange. This function helps in finding the actual direction of rotation after two orientation values are subtracted:
public float MapToRange (float rotation) { 
    rotation %= 360.0f; 
    if (Mathf.Abs(rotation) > 180.0f) { 
        if (rotation < 0.0f) 
            rotation += 360.0f; 
        else 
            rotation -= 360.0f; 
    } 
    return rotation; 
} 
  1. Also, we need to create a basic behavior called Align that is the stepping stone for the facing algorithm. It uses the same principle as Arrive, but only in terms of rotation: ...

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.