Finite State Machines: Creating Structure for your Character Control
A clean way to manage every action — from standing still to full combat.
Hello my fellow gamedevs!
I have a secret to share with you, I’m not very good at maths… and yes, gamedev have a strong relationship with maths and physics, if you are like me… should we panic and stop doing gamedev? Let me answer for you: No!
Maybe you don’t need to be in love with those pillars, but you need to keep them under control, otherwise your Game Feel… may not exist.
Acceleration
Gravity Force
Trigonometry
Many more…
I know that’s not the best realization after you coming to this post willing to learn, but no one said gamedev was easy. 😁
I want to introduce you a game development concept FSM: Finite State Machines.
officially it’s defined as…
A finite-state machine (FSM) or finite-state automaton (FSA, plural: automata), finite automaton, or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some inputs; the change from one state to another is called a transition. Source: Wikipedia
In other words, is the way to link player input with player feedback (Character response) in a consistent way. Let’s say we define the following states to control
Idle. The character is literally doing nothing.
Attack. Your character start with the first hit.
Jump. Your character jumps!
So far, this doesn’t have any major complexity, but now is when things start getting more interesting, as per definition “the change from one state to another is called a transition”
State Machine Breakdown
Let’s start really simple, at the end my intention is to simplify the understanding of this concept so it could be applied later during your gamedev session.
IDLE
On this state our character does nothing aparently, but we are switching animations and playing with our node values between transitions
Transitions.
Only executed between different states
Enter. Movement speed is decreased to 0.
Exit. Nothing
Main Loop.
Executed meanwhile the state is active.
Execute idle animation (Imagine a breathing spritesheet)
ATTACK
Our character prepare the attack and then it is executed
Transitions
Enter. We execute the preparation animation to raise the sword
Exit. Our character put the sword on the case
Main Loop.
We create a hitbox to detect collision with the enemy and then decrease his energy.
Connections or Allowed transitions between states
Now that you undertand how a player, enemy or any other object on our videogame scene could be under control by our FSM (Finite State Machine) you can think about the next iteration, connections, we could summarize this connections as rules.
You worked on your state machine for your game, you are proud of it but then you realize your player can Attack in the middle of the air and well… that was not part of your set of moves for your player.
Meaning you need to control from which states you transition to others, a well-designed state machine change the way our input will be taken under a specifc state. So player will not be able to Attack during a Jump.
Wrapping Up
Finite State Machines might sound fancy at first, but in practice, they’re just a clean way to keep your game characters (and even enemies or objects) under control.
Think of them as the “rules of behavior” for your game world:
Clear states → no confusion about what’s happening.
Controlled transitions → no impossible moves like attacking mid-air (unless you want that).
Scalable logic → the more your game grows, the more FSMs save you from spaghetti code.
Next time you design a character or enemy, don’t just code reactions on the fly—ask yourself: what state are they in, and where can they go next?
That little mindset shift can make your project much easier to build (and debug).
Thank you for reading
If this post helped you understand and learn a new Gamedev concept, consider sharing it with a fellow gamedev who’s learning.
And if you don’t want to miss the next Game Dev Pill, hit that subscribe button — Industry insight, Gamedev concepts and other building blocks gaming related straight to your inbox.