Obstacle avoidance

Now that our scene is set up, let's take a look at our avoidance behavior script. It contains all the logic for driving our agent, and applies the avoidance to the movement of the agent. In the sample project, take a look at the Avoidance.cs script:

using UnityEngine;public class Avoidance : MonoBehaviour {    [SerializeField]    private float movementSpeed = 20.0f;    [SerializeField]    private float rotationSpeed = 5.0f;    [SerializeField]    private float force = 50.0f;    [SerializeField]    private float minimumAvoidanceDistance = 20.0f;    [SerializeField]    private float toleranceRadius = 3.0f;        private float currentSpeed;    private Vector3 targetPoint;    private RaycastHit mouseHit;    private Camera mainCamera;    private Vector3 direction; private ...

Get Unity 2017 Game AI Programming - Third 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.