How are finite state machines used in games?

How are finite state machines used in games?

A finite-state machine is a model used to represent and control execution flow. It is perfect for implementing AI in games, producing great results without a complex code. This tutorial describes the theory, implementation and use of simple and stack-based finite-state machines.

How is ActiveState removed from a finite state machine?

The activeState property is no longer needed, since the top of the stack already points to the currently active state: The setState () method was replaced with two new methods: pushState () and popState () ; pushState () adds a new state to the top of the stack, while popState () removes the state at the top of the stack.

How is an FSM implemented in a class?

Implementing a FSM. An FSM can be implemented and encapsulated in a single class, named FSM for instance. The idea is to implement every state as a function or method, using a property called activeState in the class to determine which state is active: 01. 02.

How is the ActiveState property used in FSM?

The activeState property is a pointer to a function, so it will point to the active state’s function. The update () method of the FSM class must be invoked every game frame, so that it can call the function pointed by the activeState property. That call will update the actions of the currently active state.

How does the FSM get to a new state?

The update () method of the FSM class must be invoked every game frame, so that it can call the function pointed by the activeState property. That call will update the actions of the currently active state. The setState () method will transition the FSM to a new state by pointing the activeState property to a new state function.

What kind of state machine is a finite set?

A finite state machine (FSM) is a state machine where is a finite set. In a finite state machine, a system’s behavior is modeled as a set of states and the rules that govern transitions between them.