Obstacle avoidance

Now, it is time to make the script that makes our cube entity avoid the walls:

Properties of our Vehicle Avoidance script

As usual, we first initialize our entity script with the default properties and draw GUI text in our OnGUI method. Let's take a look at the following code in the VehicleAvoidance.cs file:

using UnityEngine; using System.Collections; public class VehicleAvoidance : MonoBehaviour { public float speed = 20.0f; public float mass = 5.0f; public float force = 50.0f; public float minimumDistToAvoid = 20.0f; //Actual speed of the vehicle private float curSpeed; private Vector3 targetPoint; // Use this for initialization ...

Get Unity Artificial Intelligence Programming - Fourth 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.