#State Machines — Handling largely state-independent actions

1 messages · Page 1 of 1 (latest)

silk haven
#

I'm using @fresh parrot's seldom_state to manage the behavior of my player (and soon, my enemies and NPCs), however I'm not sure how to handle actions like attacking or dashing which act separately from the core movement.

I was considering just having two statemachines, one for movement (walking, running, idling, jumping), and one for "actions" (attacking, dashing), though I'm not sure if there's a more idiomatic approach. I want to avoid have states like IdleAttack, WalkAttack, RunAttack, FallAttack, etc. which would overcomplicate the possible transitions between states.

fresh parrot
#

I'd only split into separate state machines if one set of states is mostly independent from another set of states. Like if idle, walk, run, and fall don't influence how the attack works. Also consider putting dash in the movement state machine. If you can't do one action at the same time as another across state machines, there will have to be some communication between state machines in the form of triggers. Also note, you'll have to use multiple entities to run multiple state machines. That said, the core movement of platformers (which I'm guessing is your genre), like the moving, jumping, falling, etc often doesn't benefit from a state machine, since the states' transitions aren't entirely discrete. In a fighting game, being midair and attacking transitions to an aerial state, which is not the case when you're on the ground. But this may not be the case in a platformer. So also consider making a general Moving state to represent that the player is idle, walking, falling, etc, and have other states for things that lock the player into an action with discrete exit transitions, like dashing and attacking.

Those are just some suggestions, though. seldom_state is quite open-ended, and there isn't really a canonical way to do these things

#

I'll look into compiling some of my advice on these sorts of questions on the README

#

I'd only split into separate state machines if one set of states is mostly independent from another set of states. Like if idle, walk, run, and fall don't influence how the attack works.
Well, I suppose it's fine if idle, walk, run, and fall influence how the attack works, as long as it doesn't influence much about how it transitions

silk haven
#

I like the Moving state idea, I'll try to implement that. I appreciate the input!

#

Actually... no, this won't work. I forgot the entire reason this was an issue ferris_sob
I'm at my computer now so I'll actually be able to describe this with more clarity.

#

I'm making a metroidvania / action platformer game. The current idea is the player will be able to move by walking, running, and jumping.
While moving or idling, the player will be able to:

  • attack [e.g. swinging a sword]
  • throw an item.
    While doing one of those "actions", the player shouldn't be allowed to start another "action", but should be free to move however they need to.