3D Fighting Game State Machine and Combat System Design

    \$\$This article breaks down the engineering behind 3D fighting game combat systems, explaining why a polished lobby can still lead to a poor in-match experience. It covers layered character finite state machines, input sampling and buffering, defense and throw mechanics, juggle and combo data tables, super moves with camera effects, AI difficulty tiers, local two-player synchronization, and round flow management, with practical code examples and engineering recommendations.

    \$\$## 1. Problem Framing: Why the Lobby Looks Great but the Match Falls Apart

    A common pattern in interactive content generation is that the showcase page and character select screen look polished, but the experience drops sharply once the actual match begins. This is not an art problem; it is an engineering problem in the combat system. The showcase page is a combination of static rendering and camera choreography, while a match is a hard real-time loop running more than 60 state updates per second, including input sampling, collision detection, and animation blending. The two have very different determinism requirements.

    Breaking down the in-match experience usually points to four layers:

    • State layer: Whether character behavior is strictly modeled as finite states, and whether undefined states cause freezes or clipping.
    • Detection layer: Whether hitboxes and hurtboxes stay frame-aligned with the animation, and whether active-frame drift occurs.
    • Feedback layer: Whether hitstop, screen shake, audio, and particles are synchronized. Missing hitstop makes impacts feel floaty.
    • Pacing layer: Whether the best-of-three round structure, pause, and settlement interrupt cleanly, and whether state residue remains.

    2. Layered Design of the Character State Machine

    A fighting character’s behavior is essentially a finite state machine (FSM). A three-layer structure is recommended to avoid stuffing all logic into one giant switch:

    1. Layer 1 Base: idle / walk / crouch / jump / fall / land
    2. Layer 2 Action: attack / block / throw / hitstun / blockstun
    3. Layer 3 Presentation: intro / win / lose / super_cutin

    The key constraint of layering is that lower layers do not perceive upper presentation layers, while upper presentation layers can forcibly take over lower ones. Most of the “experience collapse” at the start of a match comes from the Layer 3 entrance presentation not exiting correctly, which swallows Layer 1 input.

    1. class FighterState:
    2. def __init__(self):
    3. self.layer = 1
    4. self.state = "idle"
    5. self.frame = 0
    6. self.vel = (0.0, 0.0, 0.0)
    7. def transition(self, nxt, layer=None):
    8. # State transitions must reset the frame counter to avoid active-frame misalignment
    9. self.state = nxt
    10. self.frame = 0
    11. if layer is not None:
    12. self.layer = layer
    13. def tick(self, dt):
    14. self.frame += 1
    15. # Keep physics integration separate from state progression for replay and debugging
    16. self.pos += self.vel * dt

    3. Input Sampling and Buffering: The Core of Game Feel

    Poor game feel is often not an animation issue but dropped input. The common industry approach is to introduce an input buffer queue that pushes recent directional and button inputs into the queue and consumes them when the state allows.

    1. MAX_BUFFER = 8
    2. buffer = []
    3. def push_input(cmd):
    4. buffer.append(cmd)
    5. if len(buffer) > MAX_BUFFER:
    6. buffer.pop(0)
    7. def consume(pattern):
    8. # pattern is a direction sequence, such as [down, down-forward, forward] + punch
    9. if len(buffer) < len(pattern):
    10. return False
    11. tail = buffer[-len(pattern):]
    12. if tail == pattern:
    13. buffer.clear()
    14. return True
    15. return False

    Directional command specials (such as “down-down forward-forward + attack”) should support lenient detection, allowing extra frames in between; otherwise, new players can barely trigger them. Dashes and jumps are best recognized by “double-tapping a direction,” also routed through the buffer queue to avoid conflicts with walking input.

    4. Defense, Throws, and Juggle Combos

    Defense is divided into standing block and crouching block, and detection should distinguish high and low attacks. Throws are unblockable command grabs and require checking both hurtbox overlap at close range and the throw’s startup frames.

    Juggles and combo cancels are the source of depth and should be driven by a unified data table rather than hardcoding:

    Move Startup Frames Hitstop Cancel Window Juggle Weight
    Light Punch 4 8 Frames 1-6 after hit 0.0
    Heavy Kick 9 12 Frames 1-4 after hit 0.6
    Special 12 14 On hit only 1.0

    A combo is valid when the target is in hitstun and the current move is within its cancel window. Juggle weight determines the victim’s upward velocity and gravity decay; once the accumulated weight exceeds a threshold, the character should be forced to land to prevent infinite combos.

    5. Energy, Super Moves, and Camera Presentation

    The energy gauge usually builds over time and through offensive and defensive actions, and a full gauge unlocks the super move. A super move should include invincible startup frames, a close-up camera, and a brief global time scale. Time scaling must apply to logic frames rather than render frames, otherwise detection becomes desynchronized:

    1. def super_freeze(frames=30):
    2. global hitstop
    3. hitstop = frames # Logic pause while rendering continues, creating a close-up freeze

    Camera presentation should be decoupled from the state machine and triggered by an event bus, preventing presentation logic from polluting combat detection.

    6. AI Tiers and Local Two-Player

    Three difficulty tiers should not be just “faster or slower reactions” but layered configuration: decision frequency, executable combo length, block probability, and input error. The hard tier can read player input history for probabilistic prediction, but it should not read future frames, or the experience becomes unbalanced.

    Local two-player matches require both sides to keep logic frames strictly consistent. A fixed timestep (such as 1/60) plus 1-2 frames of input delay is recommended. Both sides exchange only input sequences, not states, which naturally avoids state desynchronization.

    7. Round Flow and Engineering Recommendations

    Best-of-three, pause, and win/loss settlement should be managed by a match-level state machine, separate from the character state machine. Pausing must freeze the logic frame counter and the buffer queue, and resuming should clear the buffer to avoid “auto-attacks after pause.”

    If the match requires cloud replay or asset distribution, general cloud capabilities can handle it: object storage for recordings and resource packs, a message queue to decouple settlement writes, and logging and monitoring with alerts to track frame rate and crash rate. The overall principles are: determinism first, data-driven design, and decoupling presentation from detection. With these three in place, the polish of the character select screen can carry through into the match itself.