Day 10 – Player Interaction States and State Machine (FSM)
Hi, I’m back.
Today, I spent more time on refactoring, focusing specifically on the player interaction system.
And yeah... it's hard.
It’s hard because I underestimated the complexity and didn’t spend enough time planning or writing a proper spec sheet beforehand. But now that I’m deep into it, I’m slowly breaking things down.
What I'm Building
The core gameplay involves different types of interactable components:
- Furniture: objects that can be summoned or repositioned
- Items: objects you can transfer to item displays
- Boxes: containers where items can be returned, similar to Supermarket Simulator
To manage these interactions properly, I decided to structure the logic as a State Machine, more specifically, a lightweight Finite State Machine (FSM).
An FSM means that the player can be in exactly one state at a time (e.g., holding an item, interacting, or repositioning) and can only transition to valid next states based on clear rules.
It makes the behavior much easier to manage and debug as the system grows.
Player State Breakdown
I split the PlayerState
into three main parts:
Holding State Tracks whether the player is currently holding a box or a single item.
Interaction State Handles whether the player is:
- Holding a mouse key (interacting)
- In the middle of a summoning action
- Actively repositioning furniture
- Hover State Tracks what the player is currently hovering over:
- Furniture
- Items
- Price tags
The Hover State is especially important because it helps the Keymap UI Controller determine which keys should be shown to the player based on what they're hovering over.
Since my game isn’t a large-scale or multiplayer-supported project (at least for now), I made the player state system a Singleton-based State Machine, and these states are updated using the Game Event System.
I’m also working on transition guards and conditions —
for example:
- If the player is already holding an object, they can still interact with certain UI elements
- But they cannot pick up another object until they drop or return the current one
I’ve also been working on the PlayerInteractionController
, but it's still a work in progress.
Once I complete the refactoring, I plan to share a detailed write-up on my studios blog.
Still a lot of polish and reorganization ahead, but breaking things down with an FSM approach is definitely making everything more manageable.
Thanks for reading — and see you in the next post!
📬 Want more updates like this?
Subscribe here to get my devlogs and new posts delivered straight to your inbox!
✨ Also, check out more detailed updates and devlogs at my BHB Studios Blog!