Book Image

Unity Artificial Intelligence Programming - Fourth Edition

By : Dr. Davide Aversa, Aung Sithu Kyaw, Clifford Peters
Book Image

Unity Artificial Intelligence Programming - Fourth Edition

By: Dr. Davide Aversa, Aung Sithu Kyaw, Clifford Peters

Overview of this book

Developing Artificial Intelligence (AI) for game characters in Unity 2018 has never been easier. Unity provides game and app developers with a variety of tools to implement AI, from the basic techniques to cutting-edge machine learning-powered agents. 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 fourth edition with Unity will help you break down AI 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. Further on, you'll learn how 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'll then learn how to implement simple ?ocks and crowd dynamics, which are key AI concepts in Unity. Moving on, you'll learn how to implement a behavior tree through a game-focused example. Lastly, you'll apply all the concepts in the book to build a popular game.
Table of Contents (13 chapters)

To get the most out of this book

The main requirement for this book is having Unity Version 2018.2 or higher installed. In Chapter 9, Behavior Trees, we download Behavior Bricks, a free Behavior Tree plugin, which requires an account with the Unity Store. In Chapter 10, Machine Learning, we will use Unity's Machine Learning for Agents Toolkit, an official machine learning platform based on TensorFlow. For this reason, that chapter requires Python 3.6 to be installed.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.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.packt.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-Artificial-Intelligence-Programming-Fourth-Edition. In case there's an update to the code, it will be updated on the existing GitHub repository.

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

Conventions used

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The AdvanceFSM class basically manages all the FSMState(s) implemented, and keeps updated with the transitions and the current state."

A block of code is set as follows:

int throwDiceLoaded() { 
    Debug.Log("Throwing dice..."); 
      int randomProbability = Random.Range(1,101); 
      int diceResult = 0; 
      if (randomProbability < 36) { 
        diceResult = 6; 
      } 
      else { 
        diceResult = Random.Range(1,5); 
      } 
    Debug.Log("Result: " + diceResult); 
      return diceResult; 
  }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Our Tank object is basically a simple Mesh with a Rigidbody component."

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