Book Image

Unity AI Programming Essentials

By : Curtis Bennett
Book Image

Unity AI Programming Essentials

By: Curtis Bennett

Overview of this book

Table of Contents (19 chapters)

Quick Path AI


Alekhine Games' Quick Path is a $10 AI that you can pick up from the Unity Asset Store. Although the next two AIs have more features, this AI is added because of its blocky nature. This block approach creates a grid-based path and is used with many types of games, but this AI works especially well with the excitement in the voxel game genre; it is suited for cubed topography.

To start with, perform the following steps:

  1. Create a new 3D scene and import the Quick Path AI from the Asset Store.

  2. Next, set up some cubes, planes, or other objects as your terrain, and then place all of these game objects into an empty game object. Name this game object Terrain.

  3. Next, on the Inspector panel, add a component, QuickPath | Grid. Immediately, you should see a series of blue lines that show up on the cubes. These indicate all the points where a character can move in the AI.

  4. Now, we need a character to move around the scene. Create a sphere, or any object, and name it NPC.

  5. Then, we'll add a Component, QuickPath | AI | Follow Mouse Object.

  6. Now, when you run the scene, assuming it is lit up and has the camera pointing where you want it to, you'll see NPC on Terrain.

  7. Click somewhere on the Terrain object, and watch the NPC object move to that point.

  8. Although we might say that the pathfinding in this is clearly working, we should also add an obstacle to the scene: something that shouldn't be stepped on. To do this, add another cube somewhere. Go to the Inspector panel for the obstacle and tag it with Obstacle by selecting that tag from the drop-down, or if it is not an option select Add Tag... and add Obstacle to the tag list.

  9. Next, in the Terrain game object, in the Grid component, expand Disallowed Tags, increase the size to 1 and enter Obstacle for the new element.

  10. Next, click on the Bake button at the top of the Grid component. Now you will see that the grid markers skipped the cube as an option. If you want to test more, click somewhere else on the Terrain object and watch the NPC object move to the clicked point avoiding the obstacle.

Now, we've seen how to set up pathfinding with Quick Path, so let's look at another way to set up pathfinding with React AI.