Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity AI Programming Essentials

You're reading from   Unity AI Programming Essentials Use Unity3D, a popular game development ecosystem, to add realistic AI to your games quickly and effortlessly

Arrow left icon
Product type Paperback
Published in Dec 2014
Publisher
ISBN-13 9781783553556
Length 162 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Curtis Bennett Curtis Bennett
Author Profile Icon Curtis Bennett
Curtis Bennett
Arrow right icon
View More author details
Toc

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.
    Quick Path 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.
    Quick Path AI
  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.
    Quick Path AI

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.

You have been reading a chapter from
Unity AI Programming Essentials
Published in: Dec 2014
Publisher:
ISBN-13: 9781783553556
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime