Book Image

Unity 2017 Game AI Programming - Third Edition - Third Edition

Book Image

Unity 2017 Game AI Programming - Third Edition - Third Edition

Overview of this book

Unity 2017 provides game and app developers with a variety of tools to implement Artificial Intelligence. Leveraging these tools via Unity's API or built-in features allows limitless possibilities when it comes to creating your game's worlds and characters. This third edition with Unity will help you break down Artificial Intelligence into simple concepts to give you a fundamental understanding of the topic to build upon. Using a variety of examples, the book then takes those concepts and walks you through actual implementations designed to highlight key concepts, and features related to game AI in Unity 5. Further on you will learn to distinguish the state machine pattern and implement one of your own. This is followed by learning how to implement a basic sensory system for your AI agent and coupling it with a Finite State Machine (FSM). Next you'll learn how to use Unity's built-in NavMesh feature and implement your own A* pathfinding system. You will then learn how to implement simple flocks and crowd's dynamics, key AI concepts. Moving on, you will learn how to implement a behavior tree through a game-focused example. Lastly, you'll combine fuzzy logic concepts with state machines and apply all the concepts in the book to build a simple tank game.
Table of Contents (10 chapters)

To get the most out of this book

  1. Be sure to download all the sample code for this book! Following along with the examples is crucial to understanding all the concepts covered.
  2. Brush up on your C# if you're rusty. This book will do its best to not leave anyone behind, but a beginner to intermediate level of understanding of C# and Unity scripting is assumed.
  3. Experiment! This book covers the core concepts, but all the examples are set up for experimentation. The reader is encouraged to build upon the given examples, to tweak values, assets, and code to achieve new outcomes.
  4. Be patient. Depending on your skill level or experience, you may find some of these concepts a bit daunting. Be sure to follow the instructions closely, and examine all the provided sample code thoroughly. AI can be a daunting subject, and while this book aims to make you feel comfortable with the core concepts, it's OK if you need to read an example more than once to fully understand all the nuances.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Unity-2017-Game-AI-Programming-Third-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Code in Action

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In fact, behaviors derive from ScriptableObject, not MonoBehaviour, so they exist only as assets."

A block of code is set as follows:

private int currentTarget; 
private float distanceFromTarget; 
private Transform[] waypoints = null; 

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "As you can see in the previous screenshot, we have Show Grid set to true."

Warnings or important notes appear like this.
Tips and tricks appear like this.