Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Unity AI Programming Essentials
Unity AI Programming Essentials

Unity AI Programming Essentials: Use Unity3D, a popular game development ecosystem, to add realistic AI to your games quickly and effortlessly

eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Unity AI Programming Essentials

Chapter 2. Patrolling

Patrolling is a simple extension to pathfinding. Instead of just having a single target in mind, we might have two or more points. We might go back and forth between them, or travel in a never-ending loop.

In this chapter, you will learn about:

  • How patrolling works
  • Patrolling in Quick Path, React, and RAIN AI packages
  • Getting to know more about behavior trees
  • Creating patrols that go to different points in a level by not always following the same path

Patrolling is a way to get an object from point A to point B and then to point C, and so on. Pathfinding is still required to get from one waypoint to another, but here, we daisy-chain them into a larger, more meaningful path.

Quick Path AI

Quick Path is back again, with built-in capabilities to handle patrol. With its simple approach to AI, only a few straightforward steps are needed to get a scene finished. Here is a breakdown of these steps:

  • Making the world ready for patrol
  • Setting up the patrol script

We'll start by expanding on our world from Chapter 1, Pathfinding the quick path demo. Stretch out a couple of the blocks to make a larger surface area. Then, click on the terrain object (the parent of all the cubes forming the terrain), and in the Inspector, click on the Bake button. You can see what happens next in the following screenshot:

Quick Path AI

If the Bake function isn't covering all the areas, you'll need to check its grid dimensions. X remains the same in the world space, but Y is actually the Z axis. You might need to increase or decrease these numbers to cover everything in the scene:

Quick Path AI

Quick Path converts the values of the Y or Z axis values internally. By default, it is set to Y as the Up/Down...

React AI

React AI doesn't come equipped with a patrol script, so we provided one. We'll start with this behavior tree script and look at how it works and how to use it. Here are the steps to reproduce it:

  1. Create a patrol script.
  2. Create a patrol AI.
  3. Set up the NPC patrol.

To start with, we've provided a script for you to use. In it, I started with the last script for pathfinding, and then I extended it to use a similar configuration to the patrol path in Quick Path's patrol script. Here are a couple of key points about this script:

  • It is based on the FollowThePlayer script from the previous chapter.
  • You can find the code in the book's contents at \Scripts\React AI\Patrol.cs.
  • It stores a public array of Vector3, so the Inspector UI can allow designers to set the waypoints.
  • Instead of the target being a player, it is set to the next waypoint in the list. Once we are close enough, it selects the next waypoint. Close Enough is the float field that allows the inspector to find...

RAIN AI

RAIN has this section put together pretty well. In reality, we only have one small section to change from the pathfinding demo, especially because the pathfinding demo had actually turned off the patrol feature.

Start with the project for RAIN AI from Chapter 1, Pathfinding. From the menu, navigate to RAIN | Behavior Tree Editor. From the editor, select FollowGreenRoad. Under Sequence is a patrol route node called waypointpatrol; select it. Finally, we have a property called Loop Type. Presently, it is on One Way, which stops at the last waypoint. You can switch it to Ping Pong or Loop, as shown in the following screenshot:

RAIN AI

Ping Pong bounces you back and forth on the path, while Loop connects the last waypoint to the first to start over.

This works when creating a typical patrolling behavior, where a character loops along a path. However, what if we want to have a character patrol an area by walking around back and forth to different points without always following the same route...

Summary

We were able to get patrolling operational in all three AIs. Each AI had its own approach.

For patrol as well as pathfinding, Quick Path had very few steps. If your need is mostly pathfinding, it does exactly what it claims to do easily. As for React, it does not have patrol out of the box, as we saw in the last chapter. However, it was not difficult to create a script that operates inside its behavior tree AI editor. This is a powerful system that you can use to allow designers to easily access and apply your awesome scripts, but you have to be comfortable programming to build the pieces for it. For RAIN, which made this about as easy as a big red button. With one setting changed, we changed the pathfinding AI into a patrolling AI. RAIN comes equipped with a huge variety of prebuilt character controlling; we looked at how to use a different waypoint system, a waypoint network, to give variety to our character when patrolling.

This concludes our chapters on setting up basic character...

Left arrow icon Right arrow icon

Description

This book is aimed at developers who know the basics of game development with Unity and want to learn how to add AI to their games. You do not need any previous AI knowledge; this book will explain all the essential AI concepts and show you how to add and use them in your games.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 22, 2014
Length: 162 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553563
Vendor :
Unity Technologies
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 22, 2014
Length: 162 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553563
Vendor :
Unity Technologies
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 103.97
Mastering Unity Scripting
€41.99
Unity AI Programming Essentials
€24.99
Unity Game Development Scripting
€36.99
Total 103.97 Stars icon

Table of Contents

12 Chapters
1. Pathfinding Chevron down icon Chevron up icon
2. Patrolling Chevron down icon Chevron up icon
3. Behavior Trees Chevron down icon Chevron up icon
4. Crowd Chaos Chevron down icon Chevron up icon
5. Crowd Control Chevron down icon Chevron up icon
6. Sensors and Activities Chevron down icon Chevron up icon
7. Adaptation Chevron down icon Chevron up icon
8. Attacking Chevron down icon Chevron up icon
9. Driving Chevron down icon Chevron up icon
10. Animation and AI Chevron down icon Chevron up icon
11. Advanced NavMesh Generation Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.8
(8 Ratings)
5 star 12.5%
4 star 25%
3 star 12.5%
2 star 25%
1 star 25%
Filter icon Filter
Top Reviews

Filter reviews by




brian Williams Mar 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I began programming a few years back, when the iOS sdk first came out; I haven't done any programming in a few years, so this book was a good catchup for me to refresh myself on working in Unity, as well as all the new stuff that has been added since I last used it.This may not be for the most advanced Unity programmer, but then again I wouldn't think anyone who's that advanced with the program would really need a book like this. There were times that I was reading things I already knew, and wanted to skip ahead, but I know that the book is aimed at many different levels of programmers, so I can't expect it only to be aimed solely at me.It was useful, and the examples were pretty relevant to the type of AI that I was looking to use in my own game.
Amazon Verified review Amazon
Heleen Durston Mar 04, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
There are many assets available for Unity that implement Artificial Intelligence (AI). Simple AIs can also be created by coding a state machine. Unity also provides Navigation Meshes which help with developing pathfinding AIs. “Unity AI Programming Essentials” by Curtis Bennett and Dan Violet Sagmiller covers 6 different AI’s that are available in Unity’s asset store. Each of the following AI solutions are presented in the form of a project that you can download from Packt Publishing’s website.Quick Path AI by Alkehine Games is available for $10 at Unity’s asset store. Its main focus is on pathfinding. The manual and a demo are available on Alkehine Games’ website. This solution is covered in Chapter one in the book and is great for beginners.React AI is by Different Methods and is available for $45 at the asset store. This asset provides a way of building behavior trees that make use of Mecanim animation and allow you to code items such as chain-of-command AIs and NPC behavior. The book discusses how to use React in chapters one, four and seven. If you enjoy coding and want to use an AI for behavior trees than this is a great choice. For more information on React visit their website. Car AI is by Bonecracker Games and is available for $10 on the asset store. All of chapter 9 is dedicated to using this AI and creating a car game demo. Smart Car allows you to set all different sorts of properties for cars. The book provides a lot of information on modifying and using this AI. You can find more information on Smart Car AI at Bonecracker Games’ website.In chapter 5 crowd control APIs are discussed. Crowd Simulation API by TechBizAccelerator is available for $45 on the asset store. ANT-Op by Gray Lake Studios is available for $75 in the asset store. Both solutions provide ways of controlling groups and defining behavior in your games. These are very specific behavior AI and the chapter provides a good overview of them. Both companies have websites that provide more information on these AI solutions.The bulk of the book covers the RAIN AI by Rival Theory which is available for free on the asset store. Their website provides excellent documentation and examples. “Unity AI Programming Essentials” provides great information on RAIN and shows you how to set-up several different AI situations that you will come across in the creation of your games. Behavior trees, attacking situations and advanced navigation meshes are all discussed and explanations are provided on how to set-up RAIN in these situations.“Unity AI Programming Essentials” is a wonderful book on implementing artificial intelligence in games created with Unity. Very little explanation is provided on AI’s in general; but for the specific situation of programming in Unity this book is great.
Amazon Verified review Amazon
Don Mar 04, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
As a pragmatist, I enjoy learning by jumping directly into features of an application like Unity 3D. This book was approachable and easy to understand--a big plus. When learning complex concepts, like AI and pathfinding, I consider approachability important for having fun and therefore avoiding the barriers that painful subjects can present.I was grateful that RAIN was free and replete with powerful features; however, RAIN does not include source code. The other assets compared within this book, Quick Path and React, offer limited capabilities, the comparison reveals key issues that Unity 3D developers should understand. I was particularly interested in an asset mentioned in the book called "ANT-Op, which simulates food searching Ant behaviors. I was disappointed to learn ANT-Op is not a asset that can be used to actually implement in my games, but rather just a learning simulator. I did appreciate the discussion and contrasts of managing driver/automobile pathfinding introductions and the other AI approaches discussed in the book. I was also grateful that a discussion of using Unity's Mecanim system works with the RAIN asset. The books introduces the basics: pathfinding, patrolling, crowds, behavior trees, sensors, adaptation, attacking, driving, animation, and NavMeshes--all important subjects in game development.My development needs are more simple than a massive, multi-user game set of tools. As a result, the simple, step-by-step approach presented in this book was perfect for my needs. The book set the course for more advanced AI and pathfinding approaches. Although I hoped for more theoretical background and mathematical constructs, it eased my way into the next level of studies. This book offers a first addition introduction to AI and an opportunity for two additional publications to augment AI development efforts with theoretical background and advanced topics.
Amazon Verified review Amazon
Chev Mar 17, 2015
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Overall the book was ok, the writing style was a little too dry for my taste. The content covered in this book was good, all about AI and its different parts. I did like how the author used different assets to do/accomplish the same thing. That way you can get a feel for how each asset handles everything and can better make a decision on what suites your needs best. Nav mesh and pathfinding was pretty straight forward as was patrolling and behavior trees. After chapter 3 things got a little more interesting, same writing style but the topics were ones I haven’t dealt with a whole lot before, and seems more interesting then the previous ones. The chapters on crowd control and patrolling were cool because I never knew how to approach these, and always thought of them to be really complicated. The chapter on driving was my favorite, I had one of those ah-ha moments and things clicked for me. When I had approached driving AI in the past I had never look into nav meshes as I thought that was only for enemies/NPC on foot lol. If it wasn’t enough to go over waypoints this chapter also hits on drifting and break zones and explains how this is AI differs from other AI due to the physics invloved. Overall the book was a little dry, but it may be due to the large topics being covered in such a fast pace. The content does have some depth, its more then click here and do this, the author explains why things are done a certain way. The topics are good and should more then cover your basic AI, and get you started with a good fundamental understanding of AI.
Amazon Verified review Amazon
K. McNamara Feb 14, 2016
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This book is a classic example of what is wrong with many coding/technical books being put out today. I dont know if it was the writers or publishers but assumptions are made that kill the content of the book. On example is in the first two chapters, in chapter one, you create a simple pathfinding route to move back and forth on. The options it shows you to stack in the behavior tree are:PARANIMATEWAYMOVEThen in chapter two after it has you create a method that picks a random location, it tells you to build the next part yourself just like you did in the first chapter only it does not work and is NOT what they show in the picture. The picture they show is stacked like this:WAYANIMATEPARMOVEBut it does not show you how to configure it this way. I have tried to redo this part over and over several times and asked several of my college friends to take a look at this and no one has been able to make it work. If a second year college student can not make it work, what good is it? I am very disappointed in this book. I dont know if the issue is with the author or due to it being 2 years old and the software changing. I have had this issue with several of the PacktPub books and will stay away from them in the future.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.