ABSTRACT

This chapter examines how to program an enemy that follows a certain patrol route and then reacts when the player comes within a certain distance. It creates an Artificial Intelligence (AI) using a design pattern called a finite state machine. Finite state machines are a series of states and transitions. Different situations can trigger transitions in the state machine so that it moves from one state to another. This allows the finite state machine to react to the game world and operate on its own. The first thing artists do to get the AI setup is add all of the relevant actors, and a playfield. Once they are done, attach the script component to Player game object. This is a simple script to move a player that can be convenient to use in a wide variety of 3D games. Next, artists need to create a new C# script called AIStateMachine. Lastly, they need to tell the AI whom to chase.