How to do it...

They use the same approach, but in terms of implementation, the name of the member variables change, as well as some computations in the first half of the GetSteering function:

  1. First, implement the Arrive behavior with its member variables to define the radius for stopping (target) and slowing down:
using UnityEngine; 
using System.Collections; 
 
public class Arrive : AgentBehaviour 
{ 
    public float targetRadius; 
    public float slowRadius; 
    public float timeToTarget = 0.1f; 
} 
  1. Create the GetSteering function:
public override Steering GetSteering() 
{ 
    // code in next steps 
} 
  1. Define the first half of the GetSteering function, in which we compute the desired speed depending on the distance from the target according to the radii ...

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.