Member-only story
Making a basic finite state machine (Godot4/C#)
Let’s discover how to implement a simple FSM in Godot!
State machines are one of the go-tool for game devs when creating AIs, or object behaviours. And, in fact, it’s not that complicated a pattern!
So, in this tutorial, let’s talk about how to make state machines in Godot 4 and C# using a hierarchy of nodes :)
However — we’re not actually going to make a character today. Rather, we’re going to focus on a simpler and less studied example, but that’s just as important, because it demonstrates how state machines can also be useful to environmental prop — we’re going to create a basic traffic light!
I know, might not sound like much; but trust me, it will teach us a lot, and it’s actually just one proof of the fact that your game environments should live and breath, too, even though they contain “inanimate” objects ;)
Of course, if you want to get this basic traffic light 3D model I made or the code for this tutorial, don’t forget to check out the Github repo with all my Godot tutorials over here :)