playMaker

Author Topic: Multiple actions simultaneously on one FSM  (Read 6966 times)

wpcain82

  • Playmaker Newbie
  • *
  • Posts: 2
Multiple actions simultaneously on one FSM
« on: December 31, 2013, 05:47:41 PM »
I want to create a simple controller for a character using w,a,s,d. The FSM will move forward by pressing "w", left by pressing "a", right with "d", and back with "s". The problem is that I cannot create an FSM that can move both forward and left (diagonally) because I can only be in one state at a time.

I created an FSM so from start state Listener I can press a key (w) and it will go to the move forward state which then translates the player forward by a certain speed. In order to return to the listener state I have "get key up" command to return and only then can I press "a" to move left. The problem is I cannot go forward and left at the same time because the FSM can only be in one state at a time.

In code this is easily done using Update function with four if statements:

function Update ()
{
        if (Input.GetKeyDown ("w"))
     {
         transform.Translate(10, 0,0);
     }

        if (Input.GetKeyDown ("s"))
     {
         transform.Translate(-10,0,0);
     }

       if (Input.GetKeyDown ("a"))
     {
         transform.Translate(0, 10,0);
     }

        if (Input.GetKeyDown ("s"))
     {
         transform.Translate(0,-10,0);
     }
}

So I can hit multiple keys at once and thereby move diagonally. I know this can be solved with a character controller with simple movement but I want to know if this concept is possible using PlayMaker because I can see other scenarios where this could apply.

Love Playmaker it is really a cool plugin and really want to develop with it. Thanks so much for your time.


Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Multiple actions simultaneously on one FSM
« Reply #1 on: December 31, 2013, 06:02:30 PM »
Setup your controls in the Input Preferences, use Get Axis, store each axis in a float, apply translation/forces multiplied by those floats. Run the actions every frame. If there is no input then the translation/force is going to be zero, meaning the character doesn't move... Therefore...

.. You can do it all in one state.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

wpcain82

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Multiple actions simultaneously on one FSM
« Reply #2 on: January 02, 2014, 01:44:54 PM »
Ok, I think I understand what you mean. But how do I get the FSM to be in more than one state at the same time? I saw the tutorial on third person controller which would solve the issue. I guess my core questions is can I have a listener fire two IF statements at once. Not for this scenario necessarily but just in general. Thanks so much for the reply, I will try out your method.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Multiple actions simultaneously on one FSM
« Reply #3 on: January 02, 2014, 01:55:56 PM »
Each FSM can only be in a single state at any given time. You can do as many simultaneous actions you want in that state, but you can't be in two states at once. By being clever you can get values every frame and do actions based on those values every frame and remain in the same state. Bool's can be a flexible tool in these situations as well, flagging the status of certain things but sometimes it can get complicated and you need another fsm anyway.

There's nothing wrong with adding more FSM's when needed. You can add more FSM's to an object, and there is some sub-fsm stuff that I'm not familiar with that may be helpful to you.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D