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
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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.
Estimated delivery fee Deliver to Ecuador

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Ecuador

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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
$19.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
$199.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
$279.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 $ 136.97
Mastering Unity Scripting
$54.99
Unity AI Programming Essentials
$32.99
Unity Game Development Scripting
$48.99
Total $ 136.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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela