Chapter 2: Finite State Machines
In this chapter, we'll learn how to implement a Finite State Machine (FSM) in a Unity3D game by studying the simple tank game-mechanic example that comes with this book.
In our game, the player controls a tank. The enemy tanks move around the scene, following four waypoints. Once the player's tank enters the vision range of the enemy tanks, they start chasing it; then, once they are close enough to attack, they'll start shooting at our player's tank.
To control the AI of our enemy tanks, we use an FSM. First, we'll use simple switch
statements to implement our tank AI states. Then, we'll use a more complex and engineered FSM framework that will allow us greater flexibility in designing the character's FSM.
The topics we will be covering in this chapter are the following:
- Implementing the player's tank
- Implementing a bullet class
- Setting up waypoints
- Creating the abstract FSM class...