Book Image

Unity 2018 Artificial Intelligence Cookbook - Second Edition

By : Jorge Palacios
Book Image

Unity 2018 Artificial Intelligence Cookbook - Second Edition

By: Jorge Palacios

Overview of this book

Interactive and engaging games come with intelligent enemies, and this intellectual behavior is combined with a variety of techniques collectively referred to as Artificial Intelligence. Exploring Unity's API, or its built-in features, allows limitless possibilities when it comes to creating your game's worlds and characters. This cookbook covers both essential and niche techniques to help you take your AI programming to the next level. To start with, you’ll quickly run through the essential building blocks of working with an agent, programming movement, and navigation in a game environment, followed by improving your agent's decision-making and coordination mechanisms – all through hands-on examples using easily customizable techniques. You’ll then discover how to emulate the vision and hearing capabilities of your agent for natural and humanlike AI behavior, and later improve the agents with the help of graphs. This book also covers the new navigational mesh with improved AI and pathfinding tools introduced in the Unity 2018 update. You’ll empower your AI with decision-making functions by programming simple board games, such as tic-tac-toe and checkers, and orchestrate agent coordination to get your AIs working together as one. By the end of this book, you’ll have gained expertise in AI programming and developed creative and interactive games.
Table of Contents (12 chapters)

To get the most out of this book

Anyone with a strong programming background will be able to get the most out of this book. However, readers that also have strong foundations in comp-sci will benefit greatly from the set of implementations in Unity.

Before you start, it is important to know about programming, data structures, and the basic foundations of C#. We assume that you feel comfortable creating scripts components in Unity, and have developed some prototypes in the past.

We believe that you will get the most out of this book if you already have an idea of the modules for beginner and intermediate gameplay scripting available at https://unity3d.com/learn/tutorials/s/scripting.

We have developed this book using Unity, Visual Studio Community, and Visual Studio Code. The latter shows better performance and behaves in the same way in Windows and Mac operating systems. The first would be our choice for a Windows-only development environment.

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-2018-Artificial-Intelligence-Cookbook-Second-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

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: "Agent is the main component, and it makes use of behaviors in order to create intelligent movement."

A block of code is set as follows:

public override void Awake() 
{ 
    base.Awake(); 
    targetAgent = target.GetComponent<Agent>(); 
    targetAux = target; 
    target = new GameObject(); 
} 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public override void Awake() 
{ 
    base.Awake(); 
    targetAgent = target.GetComponent<Agent>(); 
    targetAux = target; 
    target = new GameObject(); 
} 

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: "We also need to have the Agent script component attached to them"

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