How can I create actions that must complete before another action is allowed, while also allowing the player to input another action that will be executed after the current one? I get especially confused if I want one of these actions to involve lerping, which begs to occur in FixedUpdate.
As an example, say we want a cube (standing in for a fist or something in a weird fighting game) to lerp to a 2nd location over 5 seconds upon a keypress, while a different key would make that same cube move to a 3rd location instead; also over 5 seconds. If we want to prevent both of these actions from occurring simultaneously, but also allow the player to input instructions to move to that third location (buffering) during the final second of the cube/fist reaching location 2, how would we best do this?
your probably best off ALWAYS putting all input into a buffer class, like everything goes straight from input to buffer.
then pass it out of buffer stack into actual input and allow the buffer to fill, once the buffer is full, say 5 commands as an example, the 6th command can do whatever you think is most graceful, either clearing the buffer or for example having the sixth command take the place of the next (2nd) command which is then discarded.
That’s how you buffer input. (so like let someone press a button while doing something and store it to use after the current action completes)
as far as preventing other actions, if your talking about like for example crowd control, so someone stuns you and you can’t do anything.
in general i’d say bool checking for IsStunned is probably the best way and yes it really can get complicated.
League of Legends is one of the most popular games in the world and it has issues with new champions quite often with unintended interactions where you’d expect for example for someone to be able to do something or not and they can or cant.
Bools are best because bools are SUPER efficient, the way bools work is actually a comparison to zero.
most people think bools are 0 or 1 as true or false, in actuality. any non zero number is the same value, so 0 is true and EVERYTHING else is false. As such it’s literally looking only for a value to be 0, which is even in binary one digit. it is amazingly quick check which means the computer has no issue running tons in moments.
In the end, I decided to have different states defined by bools because it is what I knew how to do. The input was handled in Update, turning the bools for certain behaviors to true, and a bool for when an action was already being done.
In FixedUpdate, the behaviors that used time as a component were carried out, and a float inputAllowance let the player’s input be stored in Update during the last moments (inputAllowance) of that behavior. parsing that input for the move/input with the highest priority let me set that behavior’s bool to become immediately true again, when the bool preventing other actions finally became false.
In summary, I used a bool saying when to record buffered input, a bool for saying an action was already being done - preventing other actions for the duration, and a bool for each behavior that told FixedUpdate which behavior to execute.
It is messy, and I’d love to hear better ways!