> For the complete documentation index, see [llms.txt](https://docs.twgamesdev.com/uhfps/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.twgamesdev.com/uhfps/guides/state-machines.md).

# State Machines

In Unity, a **Finite State Machine (FSM)** can be used to manage movement and other behaviors of game characters or objects. FSM is a computational model that consists of a finite number of states, transitions, and actions. It works by transitioning from one state to another based on input or other conditions, performing specific actions associated with each state.

<figure><img src="/files/pyRhBqOhLPNCuYQdCbAR" alt=""><figcaption><p>Finite State Machine</p></figcaption></figure>

Instead of creating a single script that handles all movement or behavior for a game object, we can implement a more modular approach by breaking down states into smaller, individual scripts that implements Finite State Machine (FSM) methods. This approach leads to a cleaner and more maintainable solution, as it allows for easier addition and management of new or existing states.

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-type="rating" data-max="5"></th><th data-hidden data-type="rating" data-max="5"></th></tr></thead><tbody><tr><td>Adding Player States</td><td></td><td></td><td><a href="/files/WU7sHtRu0096u8BsUHwY">/files/WU7sHtRu0096u8BsUHwY</a></td><td><a href="/pages/gYuxXlRwIElQADOCxuDu">/pages/gYuxXlRwIElQADOCxuDu</a></td><td>null</td><td>null</td></tr><tr><td>Adding AI States</td><td></td><td></td><td><a href="/files/WU7sHtRu0096u8BsUHwY">/files/WU7sHtRu0096u8BsUHwY</a></td><td><a href="/pages/0QqMcTVzFlOzs7Q9ZAbu">/pages/0QqMcTVzFlOzs7Q9ZAbu</a></td><td>null</td><td>null</td></tr></tbody></table>
