> 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="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FqNlrzQDc2bEWWCPD8IjT%2Fstates.png?alt=media&amp;token=1175f3df-c909-45c3-a1d1-badbdaaa1f15" 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="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2F0modPqDVCmU264zCNbyq%2FBackground.png?alt=media&amp;token=0beb06c9-c26f-4b28-af7a-bd8454d332a5">Background.png</a></td><td><a href="/uhfps/guides/state-machines/adding-player-states.md">Adding Player States</a></td><td>null</td><td>null</td></tr><tr><td>Adding AI States</td><td></td><td></td><td><a href="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2F0modPqDVCmU264zCNbyq%2FBackground.png?alt=media&amp;token=0beb06c9-c26f-4b28-af7a-bd8454d332a5">Background.png</a></td><td><a href="/uhfps/guides/state-machines/adding-ai-states.md">Adding AI States</a></td><td>null</td><td>null</td></tr></tbody></table>
