Getting ready

We must add a new member variable to our AgentBehaviour class called weight and preferably assign a default value. In this case, this is 1.0f. We should refactor the Update function to incorporate weight as a parameter for the Agent class's SetSteering function. All in all, the new AgentBehaviour class should look something like this:

public class AgentBehaviour : MonoBehaviour 
{ 
    public float weight = 1.0f; 
 
    // ... the rest of the class 
 
    public virtual void Update () 
    { 
        agent.SetSteering(GetSteering(), weight); 
   } 
}

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.