CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Follow publication

Making a basic finite state machine (Godot4/C#)

Let’s discover how to implement a simple FSM in Godot!

Mina Pêcheux
CodeX
Published in
17 min readSep 25, 2023

--

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 :)

And as usual, since we’ll be coding our logic in C#, make sure that you have a version of Godot with .NET enabled.

Download a version of Godot with .NET support, to be able to program in C#! :)

As usual, don’t forget that you can get the demo scene and all the assets from this demo on my Github 🚀 with all my other Godot tutorials.

The tutorial is also available as a video — text version is below:

Now, with all that said, let’s discover how to setup our first finite state machine in Godot!

What’s a state machine?

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Mina Pêcheux
Mina Pêcheux

Written by Mina Pêcheux

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)

No responses yet

Write a response