1
\$\begingroup\$

I have been reading around about stack-based FSM, and I found it to be perfect for my game. However, when a character moves, it consequently have to face in some direction (and animation of each direction will be different), now the problem that I am facing in my state machine design is the scope of each state.

For example, should I divide the state into MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN or should I create one MOVE state with some direction argument in it. Now, the latter seems to be better, however, if I am to trigger direction change, how would I do it for a one-state MOVE? I could directly change the direction argument and manually change the animation sequence, which will destroy the whole purpose of state machine (State machine should change animation sequence OnEnter() state). Else, I would have complicate the state machine into hierarchy of states (Sub-states,etc.), and this seem unconvincing for me.

Or maybe I should implement some type of multiple, simultaneous states ---- Character's State (Jump, Move, Idle, Attack, etc) and Direction's State (Up down left right), then make it works concurrently, and apply stack-based architectue on Character's State only.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I find it easier to think of what you see on the screen as a state.

For example, is "MOVE" in MOVE + LEFT and MOVE + RIGHT the same visually? If it is not, then you need at least 2 different states for MOVE, and since LEFT and RIGHT are different states as well, you might be better off combining MOVE and LEFT as one MOVE_LEFT and so on.

As a counter example, is "HIT" in CRITICAL + HIT and NORMAL + HIT the same visually? Possibly. So we can have HIT as a state on it's own and CRITICAL, NORMAL as separate states.

\$\endgroup\$
1
  • \$\begingroup\$ +1 That's a neat way to think about it for small projects and new programmers. \$\endgroup\$ May 27, 2012 at 17:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .