Giter Site home page Giter Site logo

Comments (2)

Inspiaaa avatar Inspiaaa commented on May 17, 2024

Hi @TdXYZ,
the current version of UnityHFSM does not directly provide this feature out of the box. You can, however, do this fairly easily yourself:

Instead of creating just one state machine, as you normally would, you create two state machines. Then in the Update function, you call the OnLogic method of both state machines. This will run both state machines independently, in parallel.

class Player : MonoBehaviour
{
    StateMachine movementFsm;
    StateMachine animationFsm;

    void Start()
    {
        movementFsm = new StateMachine();
        movementFsm.AddState("Idle");
        movementFsm.AddState("Jump");
        movementFsm.AddState("Run");
        // ...

        animationFsm = new StateMachine();
        // ...

        movementFsm.Init();
        animationFsm.Init();
    }

    void Update() 
    {
        movementFsm.OnLogic();
        animationFsm.OnLogic();
    }
}

This same pattern can also be repeated to run as many state machines in parallel as you desire.

The implementation for running multiple nested state machines in parallel within a main state machine follows the same idea. The main difference is that their OnEnter, OnLogic, and OnExit functions would be called within an additional state that you have to add to the main state machine.

As this feature seems quite useful, I've created a new state type that does just that for you. It's called ParallelStates and will be added in the next release of UnityHFSM (2.1). If you want to already use it in the meantime, you can access it in the release branch.

from unityhfsm.

TdXYZ avatar TdXYZ commented on May 17, 2024

Thank you very much for adding this. UnityHFSM is one of the best implementations of statecharts out there. Working with the package has given me more ideas on how it can be even better such as history states and tasks, but I'll make separate issues for those.

from unityhfsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.