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 a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781783553556
Vendor :
Unity Technologies
Category :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 22, 2014
Length: 162 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553556
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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.