Replies: 3 comments 15 replies
-
@odecay @edgarssilva I think we might need to overhaul the way we currently handle inputs. For simply controlled games where one button maps to one action, the leafwing_input_manager model of putting things in nifty Input PipelineWe handle the input as an input pipeline where each step in the pipeline hands off it's output to the next step: 1. Raw InputWe have the raw user input step. This is just Bevy's giving us access to inputs, so nothing to do here. 2. "Virtual Gamepad"We use the controller settings to map that raw inputs to a virtual "gamepad". This is different than mapping inputs to actions like we do now. For instance, we may have an "attack" button, just like Smash Brothers. And pressing the attack button alone does one kind of attack. But simultaneously press the attack button and pushing the movement right will trigger a different attack. So we would do the same thing. Our virtual gamepad will have buttons such as "attack", "jump" and a directional input for "move", and whatever other buttons we need. This allows users to re-map their controls, and it abstracts the movement away, we don't care whether you use a DPad or a Control stick, etc., but it doesn't actually say anything about what kind of button combinations does what. Just what kind of buttons there are. This step will also handle determining which player the events are related to. 3. Input BufferEach player will have an input buffer that the Virtual Gamepad step will write to. This buffer will garbage collect old events by some logic whether it be number of events or how long ago the event happened. Each event will record what the event was and what time it happened.
4. State Transition Collectors & State HandlersThe current This makes it possible for us to have an "in the air" state, and have it decide to do an air attack of you press "attack" while you're in the air. It answers some of our questions about logic that we put into I think we would still want the ability for other systems to push prioritized state transition intents, because we might want that for status effects that have the ability to do a "forced takeover" of the players state, as long as it has a higher priority. What we wouldn't have is the model we have currently where the Instead the
Input Buffer Query APIOn an implementation note, I think we're going to want to be kind of clever about how we design the input buffer query API. I'm thinking we're going to want to be able to do a sort of "pattern matching" on the buffer. For example we can say, if this button was pressed, and there was a pause where it wasn't pressed that was shorter than x and longer than y, and then this button was pressed again, then trigger an attack". This should be able to be structured as a kind of query on the input buffer, and the input buffer will return whether or not the query matches the buffer's current state. We also might want these queries to be representable in YAML/JSON, so that our fighter YAMLs can specify the triggers for different attacks. Then we could have our YAML say something roughly like:
|
Beta Was this translation helpful? Give feedback.
-
Building on the idea above I think we might be able to essentially migrate to having a set of rules for when to transition out of any state, and these could be specified in the YAML. This would replace the It could be something like this: # When in this state
falling:
# Any externally triggered state with a higher priority will forcibly
# take over this state.
#
# TODO: We may not need priority if we have `immune_to`?
priority: 20
# Regardless of priority, this state will never yield to these state
# transitions.
immune_to:
# We're in the air, so ground pounds don't effect us
- ground_quaking
# What to transition to when we naturally exit the "falling" state
exit_to: idling
# Define ways to transition out of the state by user input
inputs:
# When this happens
- query:
- !Punch
- !Delay
duration: 0.1
- !Punch
# Transition to this state
to: double_air_attacking
# And another one
- query:
- !Move
direction: [0, -1]
to: quick_dropping This allows us to map the fighter state machine out pretty nicely, and make it different for each fighter with their YAMLs. |
Beta Was this translation helpful? Give feedback.
-
I also want to mention this crate and this video about tree based animation state transition. |
Beta Was this translation helpful? Give feedback.
-
Continuing discussion from #203.
Relevant wiki: Fighter-State-Machine
I'm still a little unsure about what the best practice will be as far as where to make decisions about which state to transition to. For instance, right now we have the
collect_player_actions
system making a decision, based on the fighter's inventory, what state to transition to when you press theThrow
button.This seems good in this case, but it get's a little more confusing when consider things like mid-air attacks where the same attack button might trigger a different state. Should collect_player_actions be responsible for making that decision? Or does it just depend on a case-by-case basis?
I'll post my current stream of thoughts in a comment below.
Beta Was this translation helpful? Give feedback.
All reactions