00:00
00:00
MonoFlauta
Indie Game Developer + Senior Software Engineer @ Etermax

Facundo Balboa @MonoFlauta

Age 31

Indie Game Developer

Escuela Da Vinci

Buenos Aires, Argentina

Joined on 7/30/08

Level:
27
Exp Points:
7,866 / 8,090
Exp Rank:
5,253
Vote Power:
6.87 votes
Rank:
Police Sergeant
Global Rank:
9,164
Blams:
214
Saves:
823
B/P Bonus:
12%
Whistle:
Bronze
Trophies:
15
Medals:
773
Supporter:
8y 3d

MonoFlauta's News

Posted by MonoFlauta - June 9th, 2024


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

Today I am bringing you updates for Summer Snow Day and Riverside Rumble!

Summer Snow Day

We released a new video for Summer Snow Day that you must see if you haven’t yet! It feels like everything is coming together and I couldn’t be more proud of the quality of this visual novel.


iu_1218964_2529638.webp

Our goal is to finish a demo including the first two chapters. For that, we made a list of things to polish and are pretty close to finishing it. I hope we can share it with everyone sooner so you can add it to your wishlist and try out the game! If you want to get the latest news, remember to follow Happy Ghost Studio on Twitter and Facebook!

Riverside Rumble

We had been adjusting the scope and making it more of a competitive leaderboard game or just trying to get the highest score possible as you could do in other games I worked on such as Asterash.

iu_1218965_2529638.png

Apart from that, we integrated medals for Newgrounds and I have been working on some gameplay improvements, such as using the keyboard to use the different power-ups, if you prefer that than click, and bug fixing, such as some errors that may occur after playing multiple times the game.

iu_1218966_2529638.png

That’s it for now. I am also planning other projects ahead but for now, I will focus on wrapping up Riverside Rumble while continuing with Summer Snow Day.

Thank you for reading and see you in the next update!


Tags:

1

Posted by MonoFlauta - December 11th, 2023


Hey guys! Long time since my last post. Promise I will do a year recap and have more updates next year!


At etermax we had been working on Trivia Crack VR for almost two years now and we have a lot of planned updates ahead!


We are now looking for more players that can try it out and leave us a review. If you have an Oculus Quest 2, 3 or pro, consider sending me a message and I can give you a free key!


Thank you for reading and hope to see you in the game 😁


Tags:

1

Posted by MonoFlauta - May 22nd, 2023


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

Sorry once again for disappearing for a while and for making now a Sunday DevLog post on a Monday. But! The good thing is that I have updates for every game, and most of the updates are pretty big, so let’s start!


Riverside Rumble

Roberto had been working on a bunch of feedback and assets for the Riverside Rumble game and I got to get back to it these last days. From the new assets he already created, I implemented the random sprite projectiles for the basic ones and replaced the ones for the dirt projectiles and ninja ones. Also, we added a small visual effect with the crosshair when aiming far and a wave level counter in the HUD.

iu_976892_2529638.png

Apart from that, he also polished a bunch of assets like the logo and the main menu background.

Our next steps will be adding more feedback to the crosshair on my side, specifically turning the thing red when hovering a target so you know that you are going to hit something. Then we had been also talking about making a boss so that probably will be one of our next steps.


Summer Snow Day

Last time I posted about Summer Snow Day I told you we were finishing working on Chapter 6. The truth is that we not only finished that chapter but we also finished chapter 7 and we are halfway through chapter 8 so that is quite an update.

iu_976890_2529638.webp

We think the total count of chapters will be 9 so we are almost finished with all the chapters and only polishment will be left from there. We already have a plan with Lautaro to start meeting every week once the chapters are done and re-playing all the chapters written down what needs to be improved and iterating them to ensure the best quality for every chapter.


Fight Daily! Auto Chess

I hadn’t been posting too much about this one but we had a huge update where all the units now have animations of idle and attacks. Also, a lot of assets were integrated into the UI including the in-game HUD.

iu_976891_2529638.webp

Anyway, we are still missing some UI as you can see and as always my biggest worry is the balance side. Also, we will be working on the progression of the game so that is something we need to figure out but we have already a shop system planned with art.


How to achieve a good performance in a VR game

A few weeks ago, I also made a blog post for the company I work at called How to achieve a good performance in a VR game.

iu_976893_2529638.png

It was a nice thing to be able to share some knowledge we gathered through the development process of the game I am working on my full-time job so if you are interested in VR game development please take a look at it!

That’s all for now, thank you for reading I hope to be writing updates more often than I had been doing lately.

Stay safe!


Tags:

1

Posted by MonoFlauta - January 8th, 2023


Twitter Account - DevBlog - Ko-Fi


Hey everyone!

Hope you started the year in the best possible way. I have a few updates I would like to share with you from my current projects so welcome to the first update of the year! The updates will be related to a new project, Summer Snow Day and Ostrich Run. So let’s start!


AutoChess game

For the latest few weeks, I had been working on a new game with Tyler and PigLice from Newgrounds. We basically started to talk with Tyler on my post update on Newgrounds and from there we started discussing making a game together. Later on, once we had a rough idea of what genre we wanted to do, PigLice was added to the project since he has a bunch of cool characters plus more to come.

iu_861910_2529638.webp

The idea is basically to make an AutoChess game but with the detail that the game would be single-player with collectible cards as a way to progress on it. Of course, this is a really rough idea, we had a bunch more ideas written down of what we are expecting but we are still figuring out and trying out things.

If you had been following me on Twitter you may already know some of this stuff but if not, it is a great opportunity to follow and get more frequent updates!


Almost finishing Summer Snow Day chapter 6

We had been also working on chapter 6 for Summer Snow Day which needed a bit of extra code given some new cool mechanics it has. One of these new things includes for example the possibility to pick characters to do certain actions giving a lot more freedom to the player than just showing two or three options in the dialogue system.

iu_861912_2529638.webp

The goal will be to wrap up what is left of this chapter and while we wait for chapter 7 to be written we are going to be revisiting the previous chapters and polishing stuff that we had left for later. This polishing we think will give some extra quality to the game that hopefully, will make it stand out from other visual novels.


Two new mechanics for Ostrich Run

Another game we had been working on is the full version of Ostrich Run. We made a list of the things we wanted to implement for it in case we make this full version. One of these mechanics is a pressure plate that can activate some doors for a few seconds while the other one is a water mechanic where the water goes up and down. The only way to not die drown while the water is up is by hiding the face underground like when hiding from the cameras.

iu_861911_2529638.webp

We still don’t have everything settled yet but I think this progress has been useful if we aim to have a full version of the game released someday.

Those are the updates for now, stay tuned for more, and thank you for reading!


Tags:

1

Posted by MonoFlauta - December 26th, 2022


Hello, everyone!

It is this time of the year once again when I make a huge resume of what was the year for me and what I plan for the next year! If you are interested, here is my last resume for 2021.

This time I am going to talk about Summer Snow Day, Riverside Rumble, Ostrich Run, A Toad’s Trip, Stonks, programming posts, tools, and other projects. As you can see, it will be a long post so feel free to skip a part if you are not interested in it.

That’s it, let’s start, and hope you enjoy this as much as possible as I enjoyed this year.


Summer Snow Day

We had been working a lot on Summer Snow Day this year. This year we started with having up to chapter 4 completed but, even though we just fully added almost two chapters (and probably only one or two are missing!) we didn’t stop at doing only chapters.

iu_848617_2529638.webp

We also worked on a few new mechanics that the dialogue system has. Now we can add branches to the dialogue based on the relationship status and also we finished the implementation of every minigame that the game will have.

The minigames still need art and balance we are pretty happy that those are already defined, fun to play and fresh addition to the game apart from the dialogue system. I think that one thing that is being really achieved is that in every chapter there are new mechanics and systems to discover. This, plus the plot, of course, I think will keep the player with a feeling of discovery most of the time.

This following year, the goal will still be wrapping up the plot but also we made a big plan with everything we need to poolish for the game, this will help us reach the quality we want. We will see how far we get but something I will promise for sure is that we are going to have a bunch of updates!


Riverside Rumble

We also worked a lot with Roberto on Riverside Rumble, known before as Is This Still Tennis. I think the biggest change was that we fully modified the movement of the bat which led to a re-work of almost the whole game in terms of programming.

iu_848623_2529638.png

During this remake, we focused more on some different interactions using power-ups combined with this simple mechanic of just dragging and releasing when the projectile is coming. Given the new state of the game, I think we achieved a more fun experience plus a lot more meaningful regarding strategy since before what we had was just a stick moving randomly in the air. Not only that, but Roberto also has been working on improving a lot of the sprites, animations, and effects. The game now looks a lot more alive than it was before thanks to these upgrades.

Again we are not going to rush the game, but I feel like this year we made a lot of big progress and we have a more clear goal for the game. Things that are on the list to work on are configuring levels to make them a gradual challenge and adding maybe bosses or more enemies. We will see how it develops!


Ostrich Run

The other game we are trying to make is Ostrich Run which you may have played in its game jam version when it was released. We always thought it was a game worth continuing and I guess we finally gathered the team to do it.

iu_848619_2529638.png

At first, we started doing a level editor for it to give the chance for the players to make their own levels and upload them but because of time constraints in the art team, we decided to cut this for now. Because of this, we are now focusing on the new mechanics and giving gamepad support to the game.

I think this will be the right approach since it will let us make a deliverable game in the end with less need for everyone to have enough free time. We are just starting with this but let’s see how it turns out during the year.


A Toad’s Trip

During this year, my original plan was to participate in a bunch of game jams but because of a set of different reasons I got to participate only in one and that one was the Brackeys Game Jam 2022.1, where the theme was “It is not real”. For the jam, we did A Toad’s Trip.

iu_848618_2529638.webp

I personally loved working with a lot of new people that never worked with or just worked with in my current job. Also, I had fun with the general mood of the game. I would have liked to be able to deliver a game a little less buggy but because of how things turned we weren’t able to solve every issue and a few popped up once the game was published.


Stonks

At the end of 2021, we started working on Stonks which is a meme game that uses real data to simulate buying and selling stocks and crypto. We started with the basic UI and concept and then searched for ways to just use free resources so we wouldn’t need to maintain the game.

iu_848620_2529638.webp

The game was finally released on the 26 of June. I would have liked it to have been a bit more public but I guess the game was just way too hard thing since it was a simulator that used real data. Also, it felt a bit between a simulation and a game and maybe it didn’t get to attract the correct public.

Anyway, regardless of the performance, I think it was a fun game to work on and to add to my published projects so I am still proud of it.


Programming Posts and Tools

Since last year I have been writing posts about programming. This year was no exception and I made a few new ones.

Here is the full list for this year in case you are interested:

iu_848622_2529638.webp

During this year I also made a few tools with open-source git. Some were made for personal use in some projects but wanted to share them as free meanwhile others I made them just for fun or experimentation. Here is the full list in case you want to check them out:

I think that, for this year, the tools will depend more on the opportunity to have something to work with but regarding the programming posts, I still plan to keep adding them during the year so expect more of that in the future!


Other projects

During this year I worked on a bunch of other projects that didn’t see the light yet or are not going to see it. Here is a quick recap of things I did but I will keep it on hold for now at least.

One of them was streaming on Twitch. This was something I started this year and even got to be an affiliate of Twitch but it was a very time-consuming thing and I felt like I wasn’t being able to redirect the audience to other platforms as I was trying to. Because of this, I decided to put on a hold this for now.

iu_848621_2529638.png

Another project I put on hold but definitely would like to bring back to life at some point is the Spells & Dice game. I started this as a solo project searching for an artist and I really trust that the game has what it needs to be a great game but I felt like the approach for searching for an artist for it won’t work in the end. Apart from this, I found an old team member from a game jam and we decided to work again together on a project. Because of this, I will be putting it on hold for now since I really want to focus on that one since we have already two artists on board and a pretty cool idea.

Plans for the next year

So what are the plans for next year? The main ones keep being Summer Snow Day and Riverside Rumble with a new focus on Ostrich Run and this new project that I will announce once it is more developed.

For Summer Snow Day I would love to have all the chapters finished and started with the polishment. Of course, this does not depend on me and again, we don’t want to rush the creative side so we can get the most out of the plot.

Meanwhile, for Riverside Rumble, I think that we may be able to finish the game this year, with the new focus and the new improvements for the game, the path seems a lot clearer so hopefully, we get to wrap it up.

Ostrich Run is just at the beginning of its development, so we will need to see how it develops and how much it takes us to make it as good as we want. I guess I just plan to have some good progress from this one during the year.

For last, it would be nice to start seeing big progress on that new project, but since we are just starting out I won’t promise anything, just as with the other projects, sorry for that!

This will be regarding the main projects. I would like also to go back to participate in game jams but I need to figure out how I actually want to achieve that. Also, I will keep working on programming posts and I am planning to learn new skills that I believe are useful for indie game developers, more updates on that in the future.

So that’s it! I hope you had a good 2022 year and a great 2023 ahead. Thank you for reading this far and please keep in touch!

Thank you!


Tags:

1

Posted by MonoFlauta - December 11th, 2022


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

I have a few new updates regarding Summer Snow Day, Ostrich Run, and Riverside Rumble. So let’s begin!


Chapter 6 of Summer Snow Day is officially under construction

The most significant update is that since we got to finish all the minigame mechanics and the free time events for Summer Snow Day, we are now back on track with the main chapters. Because of this, we started implementing chapter 6 which is already fully written.

iu_834301_2529638.gif

I can’t show much, and coming from me it may feel pretty obvious I would say this, but the start of chapter 6 is a really solid one with a lot of branches depending on previous decisions on old chapters plus decisions made during the chapter. I think it will give a lot for replayability or, in case you are like me and only play one time this kind of narrative games, will give you a lot of protagonism based on your decisions.


Ostrich Run new input system

For Ostrich Run we had been replanning some of our needs for the game and what we are expecting from it. First of all, in order to be able to make the whole game during the course of the next year, we plan to cut the level editor. Is something that from code we felt like it was possible with a lot of work but we would probably take a lot longer because of all the extra work that was from the art side.

iu_834299_2529638.webp

Anyway, without that, we already started focusing on the gameplay itself and improving what we had. To start, we started working on the new input system. We implemented Unity’s new input system and now the game supports playing with a gamepad which was a must that we wanted to add to the game. Next, we will be probably focusing on making more levels and improving some gameplay issues we had in the first version.


Riverside Rumble adjustments

For Riverside Rumble, FuNaNdMoRe has been implementing new animations and creating new feedback. These were added and you can check that in one of my latest tweets.

iu_834300_2529638.png

There is a lot regarding balance to do, but we have already planned on starting with that so hopefully, we will be able to start tweaking more and more the game into the final product while FuNaNdMoRe keeps tweaking the art assets to make them even cooler!

That will be, for now, probably my next post will be the resume of the year so, if I don’t write you before, please consider following my Twitter for more updates and hope you have a great end of the year with your loved ones!


Tags:

3

Posted by MonoFlauta - November 27th, 2022


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

I have news regarding Spells & Dice and Riverside Rumble. So let’s get started with the updates:


First release for Spells & Dice an update coming soon

A few days ago I published the first version of Spells & Dice at itch.io. I didn’t post it a lot since I want to show first that it is a game that will be getting some good updates every two weeks. I believe that after a few updates I will start trying to get more people interested in it and with some luck even get more people on the Discord server.

iu_820980_2529638.png

If you are interested in the next update, I already shared that it will be on next Tuesday so keep tuned for more information. But in the meantime, I will tease some of the new content that it will have. I had been making a changelog to show the progress and I can say that the update already contains a new enemy, a lot of visual fixes, a lot of new items (including a new type of item), some balance tweaks, and options for other platforms, between other stuff.

I hope that these new updates make the game a bit more interesting and dynamic but I also plan to keep iterating it will updates every two weeks so if you try it out and like it, please remember to join the Discord server to know about the latest changes!


New stuff for Riverside Rumble

We had also been working on Riverside Rumble with some new content for the game while also making plans on what to do next.

The latest updates include adding some visual effects for the armored enemy and a new kind of enemy that is the ninja one.

iu_820981_2529638.png

We had made a ninja enemy in the past but in this rework, the ninja enemy is firing a projectile that disappears for a few moments and then re-appears just before hitting. This way, you will need to pay attention to when this enemy fires and think when it will be arriving at you. Of course, in a 1:1 battle, it doesn’t feel too much, but once you fight with multiple enemies it can become a challenge!

Now our plans include adding more enemies while also start making different sets of levels to start testing how all the enemies interact between themselves and maybe have a difficulty curve that makes sense to the gameplay.

Hopefully, I will be having more updates in the near future for all the games so please stay tuned!


Tags:

1

Posted by MonoFlauta - November 13th, 2022


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

I have many new updates since it was a long time without one. The title already spoils the main news but I have some extra information to share, so let’s get to it!


Is This Still Tennis becomes Riverside Rumble

We made a list of names that we could use for Is This Still Tennis and we came up with the name Riverside Rumble. In order to come up with it, we made a list of names that we thought could be fun and voted the ones we liked the most so we are both pretty happy with it. From now on, all my updates will start using the updated name and leave behind the name of Is This Still Tennis which was a little outdated and nothing had to do with the gameplay.

iu_803357_2529638.png

Apart from the name change. We had been working on the logic for the code for the ice and fire enemy and improved the armored enemy with art and a way to break the armor if you hit it hard enough. Our current goal is to bring more enemies with more variety and to start adding levels while balancing the game since right now the current levels are just for test purposes.

For last, we made a build and tried it on Newgrounds. Luckily, it seems to be working almost perfectly, and even more, we could play it with our mobile phones so it looks like it is going to be a mobile-friendly game.


Spells & Dice is close to its first release

Meanwhile, I had been working on polishing the minimum necessary for the first release of Spells & Dice. The goal is to have version 0.0.1 pretty soon (maybe next week!) on Itch.io and from there make regular updates as I did in the past with YBit. The big difference this time is that it will take probably a long time to develop but I am aiming to build a small community in the meantime. That is why I am also releasing it for free in the beginning and also releasing it way too early. If you try it out now, you will find that is almost a really quick and small prototype, but I hope it will be the foundation for fun gameplay.

iu_803355_2529638.png

In order to achieve this build, since the last update I had been making a bunch of changes. I added a new type of enemy that is a healer, made a save system for the campaign, added a settings menu, improved the buttons, balanced them a bit more the enemies and the loot, and added some extra feedback for a bunch of small things.

I don’t think this version will be remembered or the best thing you had ever played, but I hope it gives the feeling of what I am aiming for with the main mechanic and I hope it helps me as a base to build regular updates from now on while building that community.


Finished Summer Snow Day free-time events

For last, if you had been following the updates you may know already that we have been working on Summer Snow Day free-time events. These are events where the player will be able to choose with which character they want to spend time.

iu_803356_2529638.webp

This week we finished the last free-time event that was missing, Udori’s event, and now we are ready to continue with the main plot. Apart from that, we had been making a list of all the things that are missing for the release and we have a pretty good plan for the rest of the development.

Those are the news for now! Please stay tuned and wait for the Spells & Dice release!


Tags:

Posted by MonoFlauta - October 16th, 2022


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

I have new updates regarding Spells & Dice (Dice Brawler until now), Is This Still Tennis, and Summer Snow Day. So let’s start!


Dice Brawler becomes Spells & Dice

I have been working a lot on Dice Brawler and I have some nice plans for it. First of all, I renamed the game Spells & Dice since I believe it will identify the game more clearly than Dice Brawler. Maybe Dice Brawler worked better when the game was more about different classes and you could be maybe a Warrior. Right now, I just discarded, for now, the idea of having other classes since playtesting I found that the most fun thing to play was this Wizzard class.

Now, of course, not only the name was changed. I had been also working on adding more content. Items and enemies had been added. Also a lot of extra functionality around the game like the shop and some menu options for the user.

iu_776596_2529638.png

Next, my goal is to get the game to some point where I can start sharing it. Probably going to post it on my itch.io account. But to get there, I had been replacing some art that was placeholder but copyrighted with just some placeholder art. I am not expecting to make this release as a pretty build but more to show how the mechanic is, start balancing, gather feedback and hopefully get someone interested in making art for it. So this is the news about this game, for now, I hope to bring you even more news soon!


Is This Still Tennis

For Is This Still Tennis, we are also searching for a proper name for it. This name was an old one when we just started the game idea but now it is far away from what it started as and we are already thinking of a new name.

iu_776597_2529638.png

Apart from this, we had been also working on implementing some effects for the game and some fixes on the current mechanics. Our goal now will be to add more variety of projectiles and enemies to the game before starting to maybe balance the game. If you are interested, remember to follow me on Twitter where I post more frequently, especially about this game!


More Free Time Events for Summer Snow Day

As you may know already, it is becoming more and more difficult to share stuff for Summer Snow Day because lately most of the stuff is from the Free Time Events that contain some stuff I don’t want to spoil anyone.

iu_776595_2529638.webp

Anyway, I can tell you that from the last update, we already added the Free Time Event mechanics for Rikuyo, all of them, and we are now working on Jun’s ones. With each one we work on, I am more and more convinced that this will be a great moment for the players since they will be able to share more time and get to know more about the background of their favorite character.

Hopefully, in the future, I will be able to share more about Summer Snow Day without spoiling anything from it. Maybe once we get to start working on the missing minigames!

Those are the updates for now! Thank you for reading and stay tuned!


Tags:

Posted by MonoFlauta - October 9th, 2022


Twitter Account - DevBlog - Ko-Fi


Hello, everyone!

This time I bring a tutorial on how to make Finite State Machines in Unity using C#. Though it could be done without Unity, I will use examples in Unity. Also, this concept can be taken to any language if you extract the general idea of it.

iu_771384_2529638.webp

General Idea and when you can use it

The general idea of the Finite State Machine is to have a different set of states that you can change between them. The clearest example is a character that can switch from the idle state to attack, receive damage, dead, spawn, jump, etc. Some small rules are, for example, that you can’t have by default two states at once. Of course, you can make exceptions if your game needs it but it is not the most common way to do it. Another one could be that you will have one state machine per instance to be able to switch between these states.

Even characters are probably the most straightforward example, this can also be used for other stuff like changing through screens, animation controllers (like animators), loading strategies, etc. Also, State Machines are some sort of Strategy pattern in the end, so if you are familiarized with it you will find it is pretty similar.


Making the Finite State Machine

There are many ways to do it, but this is my favorite way of doing it. But, instead of just sending you the code, let’s look part by part. First, we will be looking for the FiniteStateMachine class that will be calling some stuff from the State class, take into account that we will fill those ones after finishing this one. You can keep the methods empty until we get there. Also, if you are looking at the code in GitHub, take into account that I will simplify a bit the Finite State Machine since that one has some extra stuff that aren’t a must to add.

public class FiniteStateMachine<T>
{
}

The first thing is that each FiniteStateMachine will have an owner type. Because of that, we are going to use generics to specify the type of owner, and that way we will be able to manage it easily.

Inside the class, let’s look into the fields and the constructor for it:

private T _owner;
private Dictionary<System.Type, State<T>> _states;
private State<T> _currentState;

public FiniteStateMachine(T owner)
{
        _owner = owner;
        _states = new Dictionary<System.Type, State<T>>();
}

We will have the owner that is going to be modified for the state machine. Apart from that, we will be containing all the states in a dictionary and the current state.

Now we will have a way to add states:

public void AddState(State<T> state)
{
        state.SetState(this, _owner);
        _states[state.GetType()] = state;
}

This way, we can add new states to the Finite State Machine as soon as we start. But now let’s look at how to set a state after having them added:

public void SetState<TS>() where TS : State<T>
{
        if (_currentState != null)
            _currentState.Exit();
        if (_states.ContainsKey(typeof(TS)))
        {
            _currentState = _states[typeof(TS)];
            _currentState.Enter();
        }
}

This one is a bit more tricky. The main change is that we won’t be using a string name or something like that for the states, the best way to have it is to use the types so it becomes very natural to use. The use will feel pretty similar to GetComponent method, FindObjectOfType, and others like that.

For last, we will be adding an Update:

public void Update()
{
        if(_currentState!=null)
            _currentState.Update();
}

This way, we will be calling the Update method for the current state from a MonoBehaviour in this case.

This is a really nice start for a Finite State Machine but more stuff can be added. For example, a method for the LateUpdate or a method to get the states in case we need to check something. Also, another thing that can be done, is that when a state is added, in case there wasn’t a current state before, it will be set as the default, and maybe that way you can also ignore the null check in the Update.


The State script

For the State script, we will want something that we can have as a base class to inherit from and then code a different one for each state. Because of that, we will start by having an abstract class:

public abstract class State<T>
{
        protected T _owner;
        protected FiniteStateMachine<T> _stateMachine;
        
 
        public virtual State<T> SetState(FiniteStateMachine<T> sm, T owner)
        {
            _stateMachine = sm;
            _owner = owner;
            return this;
        }
}

From here we can also see that we will be adding a reference to the state machine and the owner. The idea is that these two fields are protected so each concrete class can access them.

Lastly, we will add a bunch of methods that can be overwritten by the concrete classes.

public abstract void Enter();
public abstract void Update();
public abstract void Exit();

The idea is that we fill the content of the methods with what we want to do to each state. This will be more clear once we apply an example to it!


Use example

To do an example, I will be using parts of the code that I had been doing for one of my games.

iu_771385_2529638.png

Here the main character and the enemies are using state machines in order to work. Each one of them has an instance of them inside the character class. Let’s take a look at the stuff that we have for the enemy.

_stateMachine = new FiniteStateMachine<BasicEnemy>(this);
_stateMachine.AddState(new EnemyIdleState(fireEveryXSeconds, animator));
_stateMachine.AddState(new EnemyChargingState(fireAnimationDuration, animator));
_stateMachine.AddState(new EnemyFiringState(projectileTarget, animator, projectileSpawnPosition, throwProjectileSound, getAnimationCurveDirection, projectilePoolName));
_stateMachine.AddState(new EnemyDeadState(animator, deadSound));
_stateMachine.AddState(new EnemyHitState(animator, damageTakenSound));
_stateMachine.AddState(new EnemyStunState(animator));
_stateMachine.AddState(new EnemyIceState(animator));
_stateMachine.SetState<EnemyIdleState>();

This is a part of the code that we have in the init class of the Basic Enemy class. As you can see, we are creating the Finite State Machine and setting a bunch of enemies. In the end, we are setting the idle state as default. This is a simple way of initializing the Finite State Machine we were working on.

Then one important thing we have is that we are calling the Update from the Finite State Machine in the Update of the MonoBehaviour.

_stateMachine.Update();

With that, we should be able to have the Finite State Machine working on the Basic Enemy class. But what about the States? Let’s take a look at the idle state for example:

public class EnemyIdleState : State<BasicEnemy>
{
}

First of all, the class inherits from the State and clarifies that is for a Basic Enemy in the generic type. This will make that the owner and the Finite State Machine types are correctly set. In the constructor, we can request the parameters we need. To keep it simple, I will only focus on the other methods. Let’s take a look for example the Enter method content:

public override void Enter()
{
        _currentTimer = 0;
        _animator.SetTrigger(IdleTrigger);
}

Here we can see that we are resetting a timer and setting the animator to trigger the Idle state. It is pretty useful to use the Enter and Exit methods to trigger animations.

public override void Update()
{
    _currentTimer += Time.deltaTime;
    if (_currentTimer >= _fireEveryXSeconds)
        _stateMachine.SetState<EnemyChargingState>();
}

Meanwhile, in the Update, we are having a timer advancing and if the time passes, then we set the state to the EnemyChargingState. This way, we can switch between states as needed because each State contains a reference to the Finite State Machine.

Small tip, try to avoid having stuff like UniRx in the states or you will need to take care of it if something external to the state wants to switch the state. Otherwise, you will execute stuff from a previous state because you didn’t dispose of it correctly.

This is just a quick example of its use but it covers creating it and a state with the Enter and Update states. Of course, you can make it a lot more complex depending on your needs.


Wrap up

So basically, you can apply a Finite State Machine to anything you want to make it have different states and switch between them. They are pretty useful because you can basically separate the logic of each state into different classes instead of having all in the main one. One good sign that you may need a Finite State Machine is that you basically have a switch with all the states and have logic in each case.

Anyway, hope you find this useful. You can look a bit more into a more complex Finite State Machine on GitHub if you want but this is already a really good start.

If you have any questions, feel free to leave them in the comments section and stay tuned for more programming posts or news about the stuff I am working on!


Tags: