Fighting Game Core System Design: From Input Buffer to Match Resolution

    This article explains how to structure the core systems of a fighting game, from requirement breakdown and fixed-timestep architecture to character state machines, input buffering, command recognition, hit detection, frame data, combos, defense, throws, quick recovery, and AI difficulty tuning. It focuses on keeping logic and presentation separate, making combat rules data-driven, and designing systems that remain deterministic and responsive under real gameplay conditions.

    1. Requirement Breakdown: Converting a Feature List into Executable Modules

    A fighting game’s feature list may look scattered, but it can usually be grouped into six capability areas: character and stage presentation, match modes, basic actions, advanced combat mechanics, AI opponents, and flow/results. Before development, each requirement should be mapped to a specific module with clear inputs, outputs, and dependencies. Otherwise, a common problem appears later: every feature works on its own, but they interfere with one another when combined.

    Common mappings are shown below.

    Feature Requirement Corresponding Module Core Concern
    Character selection, stage switching Resource and character data layer Data-driven design; avoid hardcoding character logic
    Single-player vs. AI, local two-player Controller and AI layer Unify input sources as “commands”; decouple from control method
    Blocking, throws, jumping, dashing Character state machine Legal transitions between states
    Airborne/juggle, combo cancel Hit detection and frame data system Hit reaction states and cancel windows
    Directional special moves, super moves Input recognition and meter system Command matching tolerance, resource consumption rules
    Close-up camera, slow motion Presentation layer Separation from logic clock
    Pause, best-of-three, results Match flow state machine Scope of objects frozen during pause

    Non-functional requirements are equally important. Fighting games are highly sensitive to game feel, and input-to-action response latency usually needs to stay within one or two frames. At the same time, the logic update frequency must be stable; otherwise, hit detection may sometimes register and sometimes miss.

    2. Overall Architecture: Separating Logic from Presentation

    Fighting games typically use fixed-timestep logic updates. The logic layer advances at a fixed frequency, such as 60 logic frames per second, and all hit detection, damage, and state transitions are completed within logic frames. The rendering layer runs independently at the display refresh rate and is responsible only for interpolation and drawing. The benefit is that no matter how machine performance fluctuates, the same input sequence always produces the same result. This is also the foundation for replays and online matches.

    A recommended layered structure is as follows:

    1. Input layer: collect raw keyboard, gamepad, and other inputs, then convert them into unified key events.
    2. Command layer: convert key events into combinations of direction digits and action buttons, and handle buffering and recognition.
    3. Logic layer: character state machines, hit detection, damage, and meter resolution, advanced at a fixed timestep.
    4. Flow layer: round, game, and match state transitions, as well as pause and results.
    5. Presentation layer: animation, effects, camera, audio, and stage rendering.

    The main loop can be sketched as follows:

    1. Each frame (when accumulated real time reaches the fixed step):
    2. collect raw input
    3. commandLayer.process(rawInput) # update input buffer
    4. if game is not paused:
    5. for each character:
    6. controller.generateIntent() # player or AI
    7. character.stateMachine.update(intent)
    8. hitDetectionSystem.checkCollisionsAndHits()
    9. damageAndEnergy.resolve()
    10. matchFlowLayer.checkRoundConditions()
    11. presentationLayer.renderWithInterpolation(currentState)

    Once the presentation layer is separated from the logic layer, slow motion for a close-up camera can change only presentation-layer time scaling while logic hit detection keeps its original pacing. This avoids hit detection misalignment during slow-motion moments.

    3. Character State Machine: The Core of Action Legality

    The character state machine determines what can be done right now and what state can be transitioned to next. When the state machine is poorly designed, the most common problems are a character suddenly being able to jump during hitstun, or still completing a throw after being interrupted during a throw animation.

    3.1 Basic State Partitioning

    A playable fighting character usually includes at least the following states:

    • Standing, crouching, walking forward, walking backward: movable idle states.
    • Jump (takeoff, airborne, landing): a separate set of actions available in the air.
    • Dash: forward or back dash, usually with short recovery.
    • Block (standing block, crouching block): can only be entered from legal states.
    • Attack (normal, special, super): each attack is divided into startup, active, and recovery phases.
    • Hit reaction (hitstun, blockstun, airborne): determined by the opponent’s attack.
    • Throw and being thrown: both characters’ states must match each other.
    • Knockdown and wake-up: determine when the character can act again.

    3.2 State Transition Rules

    State transitions should be maintained in tables or configuration rather than scattered across conditional checks. A simplified decision logic is shown below:

    1. function canTransition(currentState, targetState, context):
    2. if currentState is a hit-reaction state and targetState is an attack state:
    3. return false # Cannot attack voluntarily during hitstun
    4. if currentState is an attack and is in recovery and targetState is not in the cancel list:
    5. return false
    6. if targetState is a super and energy < required super energy:
    7. return false
    8. if currentState is airborne and targetState is a throw:
    9. return false # Usually cannot throw in the air
    10. return true

    Once rules are configured as data, designers can adjust the cancel list for a state without modifying core code.

    3.3 The Three Phases of an Attack

    Each attack should be clearly divided into three time segments:

    • Startup: from the beginning of the move until hitboxes appear. During this period, the character cannot block the opponent’s attack.
    • Active: the period during which hitboxes exist and can damage the opponent.
    • Recovery: the recovery time after hitboxes disappear. During this period, the character usually cannot act, making it the opponent’s counterattack window.

    The frame counts of these three phases are core parameters for fighting game balance. The frame data system later will expand on this.

    4. Input System and Command Recognition

    4.1 Unified Direction Representation

    The industry commonly uses numpad notation for directions: 5 is neutral, 8 is up, 2 is down, 4 is back, 6 is forward, and the rest are diagonals. This notation is independent of character facing, so it must be converted once using the character’s facing direction. For example, when the character faces right, “6” means forward; when the character faces left, “6” means back. Performing facing conversion in the command layer lets all state machines handle only “forward” and “back,” reducing duplicated logic.

    4.2 Input Buffer

    There is a time gap between the player pressing a button and the character actually responding, and players’ button timing is often imprecise. The input buffer records inputs from the most recent frames and allows commands to be accepted within a time window. Window length is a game-feel parameter. A common approach is to tune it across several frame values and confirm it with human playtesting.

    1. buffer = ringQueue(capacity = N frames)
    2. each frame:
    3. buffer.push(currentFrameDirection, currentFrameButtons)
    4. function detectCommand(pattern, window):
    5. search for each step of the pattern in order within the last window frames
    6. if all steps are found, return success

    4.3 Recognizing Directional Special Moves

    Take a common quarter-circle command such as “down, down-forward, forward plus attack button.” The recognizer needs to do three things:

    1. Match the direction sequence in order, allowing neutral frames in between.
    2. Allow each step to be completed within a certain number of frames; restart if timeout occurs.
    3. The final button press must appear within the same window as the direction sequence to be valid.
    1. commandDefinition = [down, down-forward, forward] + buttonA
    2. recognition process:
    3. stepIndex = 0
    4. traverse historical inputs in the buffer from oldest to newest:
    5. if currentDirection == commandDefinition[stepIndex]:
    6. stepIndex += 1
    7. if stepIndex == commandLength and buttonA is pressed this frame:
    8. trigger special move
    9. if timeout:
    10. stepIndex = 0

    In practice, direction tolerance also needs to account for analog stick values. For example, any tilt beyond a threshold can be treated as the corresponding direction.

    4.4 Super Moves and Meter

    Super moves usually require a full meter or a specified number of stocks. Meter sources include landing attacks, being hit, and blocking, and the gain from each source needs to be defined separately in configuration. Meter resolution should be completed uniformly after hit detection to avoid the same hit granting meter twice due to ordering.

    5. Hit Detection, Frame Data, and Combos

    5.1 Types of Collision Boxes

    Hit detection systems generally distinguish two types of boxes:

    • Attack hitbox: belongs to the attacker and determines whether a hit can land.
    • Hurtbox: belongs to the defender and describes the character’s vulnerable area.

    When an attack hitbox and a hurtbox overlap, a hit event is generated. The hit event must carry parameters such as damage, hitstun duration, knockback distance, and whether it causes an airborne state.

    5.2 Frame Data

    Frame data is the core table describing a move. Common fields include:

    • Startup frames
    • Active frames
    • Recovery frames
    • Hitstun after hit
    • Blockstun after block
    • Pushback distance after hit or block

    Below is an illustrative data entry. The values are only used to explain the fields and are not parameters from any actual game:

    Move Startup Active Recovery Hitstun Blockstun Type
    Example light punch 5 3 8 14 10 Normal
    Example heavy punch 12 4 18 22 14 Normal

    5.3 Combos and Cancels

    A combo means that after one attack, the opponent is hit again during hitstun. A cancel means chaining another move during the recovery phase of a move. Common cancel types include:

    • Normal cancel: after a normal attack hits, it can be canceled into a designated special move.
    • Special cancel: certain moves can be canceled into a jump or dash.
    • Super cancel: consumes meter to cancel recovery into a super move.

    Combo systems usually also need two limiting rules:

    1. Damage scaling: within the same combo, subsequent attacks deal progressively less damage to prevent infinite combos.
    2. Juggle limit: for targets that have already been juggled multiple times, subsequent attacks have weaker or no juggle effect.
    1. function calculateComboDamage(attackList):
    2. totalDamage = 0
    3. count = 0
    4. for attack in attackList:
    5. scalingFactor = scalingTable[min(count, maxLevels)]
    6. totalDamage += attack.baseDamage * scalingFactor
    7. count += 1
    8. return totalDamage

    6. Defense, Throws, and Quick Recovery

    6.1 Defense

    Defense is divided into standing block and crouching block. Standing block can stop most standing attacks and jumping attacks, but cannot stop low attacks. Crouching block is the opposite. While blocking, attacks produce blockstun and may also deal a small amount of chip damage, meaning health lost even while blocking. Chip damage is an important balance parameter and should not be set too high; otherwise, blocking loses meaning.

    6.2 Throws

    The basic rule for throws is that they cannot be blocked, but they only work when the opponent is in a throwable state. Implementation usually requires:

    • Detecting the throw hitbox against the opponent’s throwable range.
    • Throws have a separate hit window; they can be invalidated while the opponent is blocking, or a reverse window for “throw break” can be set.
    • When both characters initiate a throw at the same time, clear priority rules are needed.

    6.3 Quick Recovery

    Quick recovery refers to a fast wake-up or roll after knockdown. It is usually available only from specific hit reactions and requires the corresponding button input at the moment of knockdown. Because quick recovery affects combo extension, it should be designed together with the combo system.

    7. AI Opponent Design: Implementation Approaches for Three Difficulty Levels

    The goal of the AI opponent is not to “aim perfectly,” but to exhibit distinguishable behavior styles at different difficulty levels. Easy difficulty should make the opponent’s hesitation obvious to the player. Hard difficulty should have prediction and pressure ability while still leaving the player room to respond.

    7.1 Adjustable Parameters

    A mature approach is to split difficulty into several independently adjustable parameters:

    • Reaction time: how many frames the opponent needs to respond after observing the player’s action.
    • Decision frequency: how often, in frames, to re-evaluate actions.
    • Input accuracy: probability of mistakes or tolerance in command recognition.
    • Prediction level: whether the AI can block preemptively based on the player’s common behavior.
    • Randomness: probability of choosing different actions in similar situations.

    An illustrative configuration is shown below. The values are only used to explain the structure:

    Parameter Easy Standard Hard
    Reaction time (frames) 24 14 8
    Decision interval (frames) 30 15 6
    Input error rate 15% 5% 0%
    Predictive block probability 0% 20% 50%

    7.2 Decision Methods

    Two common approaches are finite state machines and utility scoring. Finite state machines suit clearly structured behavior, such as switching among four modes: approach, poke, attack, and retreat. Utility scoring calculates a score for each available action based on factors such as distance, meter, and opponent state, then selects the highest score or picks randomly by weight.

    1. function chooseAction(situation):
    2. candidates = [advance, light attack, block, jump, throw, super]
    3. for action in candidates:
    4. score[action] = 0
    5. if action is in attack range: score[action] += distanceWeight
    6. if opponent is starting an attack