Book Image

Unity 4.x Game AI Programming

By : Aung Sithu Kyaw, Clifford Peters, Thet Naing Swe
Book Image

Unity 4.x Game AI Programming

By: Aung Sithu Kyaw, Clifford Peters, Thet Naing Swe

Overview of this book

<p>This book fills the gap between artificial intelligence (AI) books designed to learn underlying AI algorithms and general Unity3D books written to cover basic scene setup and scripting in Unity3D. Game AI Scripting in Unity3D covers implementing AI techniques such as flocking, pathfinding, path following, and behavior trees in Unity3D with example projects.<br /><br />Game AI Scripting in Unity3D will show you how to apply AI techniques to your Unity3D projects using C# as the scripting language. Unlike other AI books and Unity3D books, this book tries to focus more on the application of AI techniques in the Unity3D engine, with sample projects that demonstrate finite state machines (FSMs), pathfinding, steering, navigation graphs, and behavior trees techniques. <br /><br />This book shows how to implement various AI techniques in Unity3D by implementing the algorithm from scratch using C#, applying Unity3D built-in features, or using available scripts and plugins from the Unity Asset Store. For example, we’ll be implementing our own A* algorithm to do pathfinding but will also explore the Unity3D navigation graphs feature. Then we’ll use the Behave plugin to construct behavior trees for intelligent AI character behaviors.<br /><br />Game AI Scripting in Unity3d&nbsp; covers other AI techniques such as flocking behavior, building a sensory system for taking inputs from the environment and other AI agents, and so on. In the final chapter this book will show you how to build a racing game AI project using Unity3D and applying the techniques described in earlier chapters.</p>
Table of Contents (17 chapters)
Unity 4.x Game AI Programming
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Priority selector


When ticked, a priority selector will query the agent through its SelectTopPriority method for the highest priority of its outgoing connections. The priority selector will then tick the connection corresponding to the returned index ID and its return value is passed on. If the ticked connection returns Running, then the priority selector will not requery priority on next tick. If a priority query returns the Unknown priority ID or an ID outside the queried set, the priority selector will return Failure.

So let's create a tree as shown in the following figure with a priority selector and three actions, Eat, Sleep, and Play.

Priority Selector

It's important to note that the orders of output connections are important, as their index values will be used to reference from the script. So, in this sample connection index, the eat action would be 0, sleep would be 1, and play would be 2. And our SelectTopPrioirty method is implemented as follows:

  private bool isHungry = true;
  private...