Tutorial
π Godot State Machine Blueprint
A ready-to-use, modular finite state machine (FSM) template for 2D Godot projects. This example features two states: Idle and Walk.
This blueprint is designed for rapid setup: simply follow the structure shown here, and you wonβt need to modify any FSM code.
Just add your own nodes, animations, collision shapes, and set the default state in the Inspector.
Perfect for player, enemy, or NPC logic in any 2D game.
β How to use
- Copy the
statemachine/
folder into your project. - Add a
player
folder with your scripts (e.g.,player.gd
,sprite_controller.gd
,idle_state.gd
,walk_state.gd
) - Set up your character scene:
- Add a root node (e.g.,
CharacterBody2D
) - Add a
StateMachine
node and attachgame_state_manager.gd
- Add state nodes (e.g.,
Idle
,Walk
) as children ofStateMachine
, each extendingStateNode
and implementing your logic. - Add a
SpriteController
node with threeAnimatedSprite2D
children (DownAnimatedSprite
,UpAnimatedSprite
,SideAnimatedSprite
) for handling animations. (Assign animations to eachAnimatedSprite2D
using your assets) - Add a
CollisionShape2D
to your character for physics.
- Add a root node (e.g.,
- Set the
default_state
property in the Inspector to your starting state. (e.g.,Idle
)
Inspector view in Godot
βοΈ Node Structure
- Character: Main entity node (e.g., player).
- StateMachine: Manages state transitions and logic.
- Idle/Walk: Example state nodes, each with their own logic.
- SpriteController: Handles animation and direction.
ποΈ Folder Structure
- statemachine/: Contains generic, reusable FSM scripts.
- player/: Contains player-specific scripts and states.
π Base Scripts
state_node.gd
This is the base class for all states. It defines the interface that all state scripts should implement.
game_state_manager.gd
Manages transitions between different states (such as Idle, Walk, etc.) for any character or game object.
Each state is implemented as a child node (extending StateNode
), and the manager automatically handles entering and exiting states, as well as calling transition logic each frame.
sprite_controller.gd
Handles sprite animation and direction for the character.
player.gd
Handles player movement, input, and updates the sprite controller.
Files
Get π Godot State Machine Blueprint + Barista Frog
π Godot State Machine Blueprint + Barista Frog
Drop-in-ready finite state machine for Godot
Status | Released |
Category | Assets |
Author | Shabby Games |
Tags | Asset Pack, Frogs, Godot, Pixel Art, Project template |
Leave a comment
Log in with itch.io to leave a comment.