O'Reilly logo

Unity 4.x Game AI Programming by Thet Naing Swe, Aung Sithu Kyaw, Clifford Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Finite State Machines

In this chapter, we'll learn how to use FSM in a Unity3D game, using a simple tank game mechanic example that comes with this book. We'll be dissecting the code and the components in this project.

In our game, the player will be able to control a tank. The enemy tanks will be moving around in the scene with reference to four waypoints. Once the player tank enters their visible range, they will start chasing us; and once they are close enough to attack, they'll start shooting at our player tank. Is this simple enough? We'll implement FSMs to control the AI of our enemy tank. First we'll use simple switch statements to implement our tank AI states, and then we'll use a FSM framework, which is based on and adapted ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required