playMaker

Author Topic: Should I use multiple FSMs for similar character controllers?  (Read 1993 times)

JOY

  • Junior Playmaker
  • **
  • Posts: 51
  • From JOY Entertainment
    • JOY Entertainment
Should I use multiple FSMs for similar character controllers?
« on: December 08, 2016, 04:06:02 AM »
Hi,

I currently have normal set of character with lot of controls and checks: Run, Jump Left/Right, Double Jump, Roll). They were split into "Left and Right" and "Jump and Roll" FSMs.
Now I plan to add attack controls/actions which are similar with normal movements: Jump Left Attack, Jump Right Attack, Roll Attack. The only difference is: Those actions only happen when user meets enemies.

Reference:
So my question is: should I add new controls to current FSMs (which is quite big and complex already) to reuse the current actions and check? Or should I add new FSMs which will use a lot of similar States and FSM actions?

Update:
I tried to add check state to every action state of normal movement like:
 - If IsEnemyAround = True -> Send and Event to "Attacks" FSM
 - If IsEnemyAround = False -> FINISH -> Continue to next State.

However, It still add many states to current FSM ones. And I don't know how to switch back to normal movement after finish that Movement on "Attacks" FSM since cannot send event back.

Thanks.
« Last Edit: December 09, 2016, 07:07:16 AM by JOY »

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Should I use multiple FSMs for similar character controllers?
« Reply #1 on: December 08, 2016, 05:56:48 AM »
Having multiple FSMs at once isn't a big performance issue, in fact all of my gui is split into different FSMs on Menu Manager and I haven't noticed any drops in fps or increase in cpu.

It's easy to check anyway, turn on your statistics in unity. setup simple loop that can generate random numbers,  launch two of these at the same time in one fsm, and then log the stats, then put them in the same gameobject but in two different fsm and launch them at the same time again with events.
« Last Edit: December 08, 2016, 06:02:38 AM by elusiven »

JOY

  • Junior Playmaker
  • **
  • Posts: 51
  • From JOY Entertainment
    • JOY Entertainment
Re: Should I use multiple FSMs for similar character controllers?
« Reply #2 on: December 08, 2016, 08:34:18 AM »
Hi elusiven,

Thank you for your input. It's not about performance. It's about the complication if I use too many states in one FSM which it's very hard to control. 
For the second option, I'm concerning that there will be many similar states between 2 FSM?

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Should I use multiple FSMs for similar character controllers?
« Reply #3 on: December 08, 2016, 09:35:33 AM »
Hi,
If you need to be able to control different things simultaneously it is better to do in multiple fsm's

As example you could do something like this :

For your attack you should make a separate fsm and make way to check if player is moving left/right, in air. on ground or rolling using variables.

so in your 'left and right' fsm you could set a bool when going left or right

then for the roll/jump/double jump you could use an int, 0 for roll 1 for normal 2 for run 3 for jump and so on

the you can use "bool test" and "int switch"

JOY

  • Junior Playmaker
  • **
  • Posts: 51
  • From JOY Entertainment
    • JOY Entertainment
Re: Should I use multiple FSMs for similar character controllers?
« Reply #4 on: December 09, 2016, 06:58:22 AM »
Hi,

It seems that I'm not clear with my question. I added the FSM for Left Right and Jump Roll movements in the first post together with the referenced game