3D Fighting Game Engine Architecture and Combat System Design Practices

    This article walks through the architecture and combat system design of a 3D fighting game prototype, covering a layered flow-logic-presentation structure, frame-driven finite state machines, two-player keyboard input arbitration and buffering, hit detection with combo and cancel rules, three-tier AI difficulty, round and pause flow management, decoupled presentation and close-up cameras, plus performance and maintainability practices with a phased delivery roadmap.

    1. Problem Background and Goal Breakdown

    The original requirement described a typical 3D fighting game prototype: a home screen showing two standalone characters on a rainy rooftop stage, plus single-player against AI (easy, normal, hard), local two-player versus, character selection, best-of-three rounds, and combat mechanics such as guarding, throws, jumping, dashing, juggling, and combo cancels. It also included directional special moves, a full-energy super move, close-up cameras, pause, and win/loss results.

    The most common reason projects like this fail is not “the home screen looks bad,” but that the home screen and the battle scene are driven by two mutually incompatible sets of logic. The home screen is static display plus camera animation; combat is high-frequency state updates and input response. If both share the same object lifecycle, you get stutter when entering a match, leftover character state, and dropped inputs. So the first step is to split the requirements into four subsystems that can evolve independently:

    • Presentation layer: home screen, character select, stage, close-up cameras, results screen;
    • Combat layer: state machine, hit detection, combo and cancel rules;
    • Input layer: local two-player key mapping and input buffering;
    • Flow layer: match format (best of three), pause, AI difficulty switching.

    2. Overall Architecture: Layers and Lifecycle

    A three-tier structure of “flow control — combat logic — presentation rendering” is recommended, with layers communicating only through explicit data contracts.

    1. FlowController (match format / pause / scene switching)
    2. ├── BattleSession (lifecycle of a single round)
    3. │ ├── FighterState × 2 (state machine + resources)
    4. │ ├── InputService (two-player input arbitration and buffering)
    5. │ ├── AiController (three difficulty strategies)
    6. │ └── HitResolver (hit detection and damage settlement)
    7. └── Presentation (stage / camera / effects / close-ups)

    The key principle: the home screen character and the battle character are different objects. The home screen only handles display and transitions; when a match starts, the flow layer creates a brand-new BattleSession, and destroys it entirely on exit. This avoids leftover state and eliminates problems like “entering the game feels off” at the architectural level.

    3. Combat Core: Finite State Machine and Frame Driving

    A fighting game is essentially “discrete states + frame counting.” Each character maintains a state machine with states such as idle, walk, jump, crouch, guard, hitstun, juggle, throw, dash, and special move.

    1. class Fighter:
    2. def __init__(self, hp=1000, energy=0):
    3. self.state = "idle"
    4. self.frame = 0 # frames elapsed in the current state
    5. self.hp = hp
    6. self.energy = energy # 0~100, full energy unlocks the super move
    7. self.airborne = False
    8. def change_state(self, new_state):
    9. self.state = new_state
    10. self.frame = 0
    11. def tick(self, input_cmd, opponent):
    12. self.frame += 1
    13. # 1) Timeline logic of the state itself (e.g., hitstun ending)
    14. # 2) Input priority arbitration (see section 4)
    15. # 3) Position and collision box updates
    16. # 4) Hit interaction with the opponent (see section 5)

    Key points:

    1. Fixed frame rate: logic advances at a fixed step (e.g., 60 frames per second), so render frame rate changes do not affect detection, avoiding balance issues like “special moves get stronger on high-refresh displays.”
    2. State transition table: drive behavior with a current state × input/event → target state table instead of large if-else chains that become unmaintainable.
    3. Juggle and gravity: being juggled is an independent flag combined with vertical velocity; on landing, switch uniformly to a knockdown state, which makes it easy to plug in combo counting and protection mechanisms.

    4. Input Layer: Arbitration and Buffering for Two Players on One Keyboard

    The biggest engineering challenge in local versus is input conflict and recognition latency. Common approaches and cautions:

    • Key zones: the two players use physically separated key regions to avoid key lockout caused by scanning the same matrix;
    • Input buffer: maintain a command queue roughly 8–12 frames long, used to backtrack-match “combo cancels” and “directional special moves”;
    • Directional pattern recognition: match patterns over the most recent frames of directional input, e.g., “down, down-forward, forward + attack” counts as a special move; set a timeout window to prevent misfires;
    • Priority: special move > throw > guard > normal attack; when multiple inputs land on the same frame, pick a single action by priority.
    1. def resolve_input(buffer, now_frame, window=12):
    2. seq = [d for (f, d) in buffer if now_frame - f <= window]
    3. if match_pattern(seq, ["down", "down_forward", "forward", "attack"]):
    4. return "special_move"
    5. if "guard" in seq: return "guard"
    6. if "attack" in seq: return "attack"
    7. return "idle"

    5. Hit Detection, Combos, and Cancel Rules

    • Hitboxes: the attacker spawns an attack box, the defender has a hurt box, and intersection is tested every frame; one attack settles only once against the same target, deduplicated by attack instance ID.
    • Guard: distinguish high/low attacks and air guarding; a successful guard enters block stun and drains a small amount of energy, preventing infinite turtling.
    • Throws: only work at close range when both sides are in a throwable state; on success, enter the throw animation and stun, unaffected by normal attacks.
    • Combos and cancels: define a cancel_window (the frame range in which canceling is allowed) and the set of target actions each move can cancel into; the next action is only allowed when the current move is inside its cancel window and the hit connected, which rules out infinite combos by design.
    • Energy and super moves: landing hits, taking hits, and guarding build energy; at full energy, all energy is consumed to trigger a super move with brief invincibility and a camera sequence.

    6. Three AI Difficulty Tiers: Explainable Strategy Layers

    Don’t fake difficulty by “doubling the numbers.” A layered implementation is recommended so the differences between the three tiers are explainable and tunable:

    1. Easy: decides at fixed intervals with high reaction delay (e.g., 12+ frames), low guard probability, and almost no special moves;
    2. Normal: adds distance awareness and basic combos, guards probabilistically, uses special moves when energy is sufficient;
    3. Hard: shorter reaction delay, capable of combo cancels and counters (attacking during the opponent’s startup), and holds energy waiting for a better opening.
    1. class AiController:
    2. def __init__(self, level): # level: 0 easy / 1 normal / 2 hard
    3. self.level = level
    4. self.reaction = [14, 8, 4][level]
    5. self.guard_rate = [0.1, 0.4, 0.7][level]
    6. def decide(self, self_f, opp, frame):
    7. if frame % self.reaction != 0: return "idle"
    8. dist = abs(self_f.x - opp.x)
    9. if opp.state == "attack" and random() < self.guard_rate:
    10. return "guard"
    11. if dist < 1.2 and self_f.energy >= 100:
    12. return "super"
    13. return "approach" if dist > 1.5 else "attack"

    7. Flow Management for Match Format, Pause, and Results

    • Best of three: the flow layer maintains round_index and each side’s round wins; when a round ends, go to the round transition first, then reset character state and the stage rather than rebuilding the whole scene;
    • Pause: while paused, freeze logic stepping and input sampling but keep rendering, and have the UI layer show a menu; on resume, clear the input buffer so keys pressed during the pause aren’t misread as combo input;
    • Results: show round wins, remaining HP, max combo count, and elapsed time, and offer two paths, rematch and return to home; rematch uses “reset” rather than “rebuild” to reduce the chance of stutter.

    8. Presentation Layer: Decoupling the Stage and Close-Up Cameras

    A stage like a rainy rooftop contains rain particles, wet-ground reflections, and distant lights; this is purely presentational content and should not enter combat logic. Close-up cameras (super moves, the deciding moment) are best implemented as “logic pause + presentation takeover”: on trigger, the combat layer freezes briefly, the camera system plays along a timeline, and control returns afterward. This keeps the sequence stable and prevents camera switches from affecting hit detection.

    9. Performance and Maintainability Checklist

    • Reuse characters, effects, and hit instances via object pools to avoid frequent allocation during a match;
    • Separate logic from rendering: fixed-step logic with render interpolation;
    • Cap the number of hitboxes and trim by priority when the cap is exceeded;
    • Externalize key parameters (stun frames, cancel windows, energy gain rates) as configuration for easier balance tuning;
    • Build replayable “input — state — detection” logs to help locate issues like “combos don’t trigger” or “special moves misfire.”

    10. Suggested Delivery Roadmap

    In phase one, get the minimal loop working: home screen → character select → single match → results, keeping only idle, attack, guard, and hitstun. Phase two adds jumping, dashing, juggling, and combo cancels. Phase three brings in the three AI tiers and local two-player. Finally, polish close-up cameras, pause, and the match format. If cloud capabilities are needed, generic service categories can carry them, for example object storage for configs and replays, a container platform for deploying match services, and a logging service with monitoring and alerting to track anomalies, so effort stays focused on combat feel as the core competitive strength.