I’m working on a 2d platformer prototype, the whole point is learning.
And I was wondering what I’ve stuck right now.

I’ve a Finite State Machine for the movement, jump, fall and so on. And was wondering, should I have another state machine for the action, like shooting, melee, bow? I’m trying to understand the benefits of having two separated state machines for this prototype, and what would be the cons of it.

Have anyone played with this idea?
What was the results?

  • Jeffool M
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 days ago

    Mind you I’m no expert, but I don’t see a downside in making player-state a single FSM. It even makes things like (FALLING && MELEE) a single check, and you could add in bonus damage in the attack.

    • Shin@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      2 days ago

      Kind of get it, But I would have a “Move”, “MoveAndShoot” and so on, For each dual combination, and if I do have Sword, Shoot and Kick, that will scale quickly. But, I don’t know if it’s worth it in the end. Some ideas looks pretty awesome when you start, and quick becase bad when you implement.

      • Jeffool M
        link
        fedilink
        English
        arrow-up
        2
        ·
        21 hours ago

        Some ideas looks pretty awesome when you start, and quick becase bad when you implement.

        Ain’t THAT the truth!

        But I was thinking of using a bit field. Just create an enum of individual statuses with each one doubling in value. (MOVING_LEFT = 1, MOVING_RIGHT = 2, next = 4, next = 8, etc.) Then add a last one as TOTAL_NUM_STATUSES, and create a field of that size. So then each status update is just turning on/off that enum’s bit, and if you’re doing multiple then just check the field against those enums. It also keeps you from having to do any combinations.

        Does that make sense the way I’ve described it? Maybe I’m overthinking it. The most important part is that you understand it and can progress in your work, after all.

        • Shin@piefed.socialOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          20 hours ago

          This looks promising. I never imaged to use this idea.

          I think I want to make a base implementation class for this.
          There is a few caveats on this, for example the “Run” and “Move” can be activated at the same time on this concept, which isn’t a thing. So I need to validate the state on this. But the concept is interesting.

          Thanks @[email protected]

          • Jeffool M
            link
            fedilink
            English
            arrow-up
            2
            ·
            18 hours ago

            Good luck! It was apparently a common way to save space back in the day? I went to school like 20 years ago at Full Sail to learn this stuff, though I never went into the industry.

            It was first taught to me as a way to keep things small, anyway. I think they can run a tiny bit slower, for the record. But it makes things WAY more readable for me as well.