Finite-state machines (FSMs) divide logic in a finite number of states. They are great for most prototypes as they allow writing complex behaviors in a single class, while keeping the code clean. Because PreviewLabs is using FSMs quite extensively, I thought it would be interesting to have a closer look at PlayMaker.
The PlayMaker plug-in allows you to add a FSM component to any Unity3D GameObject, and define the states and their logic in a visual way, using the FSM Editor.
On the left side of the editor, you can see the states of the FSM. At the right, you see the actions defined for the selected state. Most of these actions allow you to access the Unity API functionality, but you can also write your own actions.
Because FSMs are perfectly suited to implement AI, I used PlayMaker to make a simple game where the player has to avoid being shot by a cannon. PlayMaker allowed me to get a quick first result, but as the game evolved and got more complicated, the series of actions got more complicated too.
While you would expect visual programming to give you a better overview of your game logic, implementing the behavior for the states was a very confusing experience. To be honest, it’s a lot easier to write code to implement this – at least from a programmer’s point of view.
Is PlayMaker then all bad for us? No, the one thing I really find interesting and useful is that it can give you a visual overview of a FSM and its transitions, while allowing you to change the FSM by linking states in a different way.
In a next blog post, I will explain you more about how you can get the best from both worlds.