- Home /
a better approach than state machine for character controller
hi, i'm trying to create an advanced character controller for my player, i tried state machine using interface to achieve a better way to change player state but i ran into a problem : let's say while player jumping received a damage that killed him in this case the player is both dead and falling dead state limits any kind of movement, the player would remain dead in air this case, i can just put a bool if Dead and not Grounded then apply gravity but there is so many cases like this, and patching them like that creates the problem that i'm trying to avoid using state machine in the first place simply i' looking for a better way of managing more than one state at a time with limitation to what states can work together and sorry for my bad english
Answer by logicandchaos · Jun 09, 2020 at 11:50 AM
You need more than one state machine or a non finite state one. For a FSM to work there must only be one state active at a time, if there are 2 things that can happen at the same time they can not be in a FSM together. You either need need a second FSM or a non finite state machine. You don't want to avoid a state machine, you want to use a different kind.
What I did to avoid adding bools and ifs was create an informal fuzzy pattern matching state machine. I created an abstract class condition with a virtual function check that returns a bool. Then I can make anything a condition and my actions have a list of conditions and my character has a list of actions. Then I just sort the list by the most conditions and loop though the 1st match I break out of the loop and set a bool canAct, the bool is reset with an invoke call.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000430im_/https://answers.unity.com/themes/thub/images/avi.jpg)