There are many methods in approaching this, and one of them is using a decision model called a Finite State Machine (FSM).

A state machine is a very useful model in which the possible conditions of an agent are divided into “states”, which can have “transitions” into and out of each other under defined conditions. This is a concept used in many automatic decision-making implementations, including AI programming in games. In fact, Unity’s animation controller uses the state machine concept to model animation behaviors.

In this tutorial we will implement an FSM-based character AI in the context of a point-and-click real-time-tactical combat game in Unity.

Enemy characters are expected to be on the lookout for the player characters, attack any within sight, pursue any who try to escape, and try to escape combat themselves when their health is below a certain threshold. Within the tutorial an introduction of the Unity project to be worked on is also included.

Prerequisites

Before starting this course, you should be familiar with C# programming in Unity and the concept of 3D transforms as it is used in the engine. Although the concept of the state machine itself is also introduced in the tutorial, it would also help if you read up on it first.

Also, it should be noted that the game project in this tutorial is controlled using the Unity Remote 4 app, so make sure you have it installed in your device.