Search Unity

Fighting game 'Input stream' in unity

Discussion in 'Scripting' started by Voodin, Mar 29, 2020.

  1. Voodin

    Voodin

    Joined:
    Apr 19, 2018
    Posts:
    48
    Fighting games get the most functionality out of a minimal quantity of buttons by requiring sequences of buttons to be pressed in quick succession, certain fighting games and action games such as Devil May Cry also include delay attacks which require the player to wait for a period of time before pressing a button for a different result, ie: "Ten Hit Combos" In Tekken. How would one accomplish this in unity? I have a few ideas but I'm not confident in my unity and general programming knowledge right now:

    Possibly I could: have a constant timer for button inputs, and an array for which inputs were pressed and how many frames(or milliseconds) apart they were pressed. For each technique a character can perform, have some sort of check for if the proper sequence and timing was performed to execute the move.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    I've never actually implemented this but I imagine one way to model a particular move (like Hadouken) with a series of required inputs, and give timing parameters for them.

    So you'd have a list that contains four "move input" entries: Down, Down-forward, forward, punch.

    Each one could specify conditions to accept it, such as when you punch you still need to be holding forward for it to count.

    Timing parameters for each item would be minimum time between inputs, maximum time between, and also maximum variance between the timings (importance of a steady rhythm).

    While the game is being played, all the move-watchers would each have their own set of target moves, and the Hadouken one would be waiting to see a down input. If it saw a down input, it would start its own internal timer, then start looking for a down-forward within a reasonable time window, etc.

    If it ever failed to get it, the Hadouken watcher would just revert to its neutral state.

    If you made it through all moves, meeting all criteria timing-wise, then a fireball would blast out of your fingers.

    If you want to "grade" the player on how well he did the move, you could analyze the overall move for speed, or for steady cadence, and the more speedy (or rhythmic) it is, the larger the Hadouken damage is.
     
    Nefisto likes this.
  3. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    I would remember the last time a key was pressed, and on new key press find the time difference and see if it's 'within acceptable delay'. If it is, see if it applied to any combos and if the combo is finished apply the combo. If it's outside the range (eg more than 1 second), then just clear your 'combo keys pressed' and start over.
     
  4. Voodin

    Voodin

    Joined:
    Apr 19, 2018
    Posts:
    48
    From this I'm piecing together that I could possibly use an observer pattern, and with a given input I can notify observers who's required inputs start with the given input, thus starting an internal timer on each of these observers. If the timer were to either timeout or the incorrect following input were to be performed then the observer would return to its initial state. however if the required series of inputs were performed with proper timing the move would occur.

    And an observer would keep track of:
    1.each input needed
    2. the time between inputs
    3. the quantity of inputs

    The observer would be able to then do whatever sequence afterward. 20200329_142009.jpg 20200329_142059.jpg something like this?
     
    Primoz56 likes this.
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    This certainly sounds reasonable to me. Give it a whirl and post us back a full report, maybe someone else will find it useful.
     
  6. bimbim18

    bimbim18

    Joined:
    Nov 26, 2018
    Posts:
    1
    Hello!
    did you manage to implement control?
     
  7. Voodin

    Voodin

    Joined:
    Apr 19, 2018
    Posts:
    48
    not yet, I've tried multiple methods but I can't find one thats fool proof. The Observer listener pattern was not the way to go, that only caused headaches. I attempted a coroutine pattern, but I couldnt figure out how to fully implement it.

    Though I havent been working on this idea that often
     
  8. magehuntz

    magehuntz

    Joined:
    Mar 24, 2017
    Posts:
    27
    Hello! I know this thread is old, but since I'm developing a fighting game myself, why not give my 5 cents oj the subject. The way I'm planning to do it is keeping an array of pressed inputs, exactly how you see them on training mode inside street fighter. Then, on each input, the game check if that input is the end of a combo, and if the timing is tight enough, the special move is executed. You will have to keep the button combinations of the combos of each characters stored inside a data structure somewhere, but I found it to be the most fool-proof way to approach that.
     
  9. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    This is what I would do —-


    Create a script with a list or array. String.

    using a timer, at every interval remove element 0 from the list, add new empty frame element to end of list.

    on each button press, log the keypress into the list to the end of the list. .

    as the list act like a timer. Removing 0 and adding it to the end, On every removal of element 0, you can have a secondary list is = to the first 10 elements of your primary list x if the player executed high punch high kick crouch forward and block and the strings all read, and if it does ; execute the animations.

    so a list

    forward
    Empty
    Empty
    Down
    Empty
    Block
    Empty

    is ticking upwards, and executing the command, at 0, on frame; while then you check the upcoming frames to see if that command is associated with a special move or Combo, and if such play this animation instead.