Finite State Machines - Falmouth-Games-Academy/comp250-wiki GitHub Wiki

Overview

Each state a being,
Back and forth the ebb and flow,
We are all cycles

A finite state machine or FSM is a construct of states, actions within the states, and transitions between them. FSMs were a common feature in-game AI up to the early 2000s [1]. In this application, the state can reflect the action of the agent, such "chasing player". The transitions are the conditions that make them change to a different action, such as "player picks up death ray", wherein the state will subsequently change to a different one, such as "run away".

A finite state machine can be implemented in a multitude of ways. Hand-programming using function delegates or enums as state descriptors is possible; however, some game engines provide visually-oriented approaches alternatives. Unity, for example, utilises state machines for its animation system [4].

Pros

  • FSMs are relatively simple to understand and easy to illustrate as simple diagrams [2], using modelling languages such as UML [5].

Cons

  • As AI becomes more complex, FSMs can prove inefficient, as the number of potential states required grows exceedingly large [2].

Example

A simple finite state machine in action A simple example of a state machine used for character control. Image from [3]

In the above example, the possible actions of the player are described in a simple state machine. From a standing state, the player has the ability to duck or crouch by pressing different buttons. Their current state affects the abilities they can use, i.e. the transitions they can take.

This example also illustrates a disadvantage of state machines. For example, a player may want to jump while crouching. Not only that but perhaps they would like to dive as they are falling, not just jumping; but should also be unable to dive if they are falling while ducking. As the number of potential combinations of states increases, the graph becomes more complex [2, 6], and could be replaced by an alternative, such as a fuzzy state machine [6] or behaviour tree.

References