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)

What this book covers

Chapter 1, The Basics of AI in Games, gets the reader up to speed with the basic terminology we'll be working with. In order to build up to the more advanced concepts in the book, we first lay the groundwork and expectations for the following chapters. This introductory chapter provides a preview of some of the concepts covered and prepares the reader with the necessary knowledge to be successful in the sample projects and code to follow.

Chapter 2, Finite State Machines and You, jumps right into one of the most essential concepts in game AI--the finite state machine. The chapter starts with a conceptual overview and then dives into an implementation of a state machine in Unity using the built-in features, such as Mecanim and StateMachineBehaviours. This chapter is the first to take the user through an actual example and sets the tone for how future chapters will explain the concepts they cover.

Chapter 3, Implementing Sensors, builds on the concept of the AI agent by providing the reader the knowledge and techniques to make their AI more believable. In this chapter, the reader learns how to implement sensing for their agents, allowing them to collect data and information from their virtual surroundings, thus enabling more complex interactions with their environment. The output of the agent is only as good as the input, and this chapter ensures that the reader can implement sensing mechanisms to give AI behaviors solid inputs to base their algorithms on.

Chapter 4, Finding Your Way, takes the reader's knowledge to the next level. With the skills from the previous three chapters to build on, the reader is now given the tools to have their AI agent navigate the game world. A few different alternatives are explained in detail, such as node-based pathfinding, the near-standard A* algorithm approach, and finally, Unity's NavMesh system. Examples are provided for each, and the user is given the necessary knowledge to pick the right approach for each situation.

Chapter 5, Flocks and Crowds, covers the history and implementation of a standard flocking algorithm. Along with some history on the topic, the user is walked through a sample project that implements flocking to create convincing boid systems to model birds, fish, locusts, or any other flocking behavior. In the later portion of the chapter, the reader is introduced to implementing simple crowd dynamics using Unity's NavMesh system. Once again, sample scenes are provided to illustrate the different implementations.

Chapter 6, Behavior Trees, showcases another handy tool in the AI game programmer's tool belt: the behavior tree. The chapter teaches readers the concepts behind behavior trees, walks them through a custom implementation, and applies the knowledge learned in two examples: a simple math-based example and a more fun and frankly silly example we call HomeRock, which emulates a popular online card game to showcase behavior trees in action.

Chapter 7, Using Fuzzy Logic to Make Your AI Seem Alive, sets the stage with a long and descriptive title, right? This chapter covers the fundamental concepts in fuzzy logic and the approach for converting fuzzy values to concrete values and explains a simple approach for implementing fuzzy logic in Unity. The first example illustrates the simplest possible version of the concepts, and the second example illustrates a morality/faction system like you'd find in an RPG to illustrate the usefulness of fuzzy logic.

Chapter 8, How It All Comes Together, takes concepts the reader has learned throughout the book and throws them into a sample tower defense example project. This chapter illustrates how, by taking a handful of AI techniques, you can quickly throw together a game that implements AI NPCs and enemies and gives them rudimentary decision-making abilities.