3D Fighting Game Engine Architecture and Implementation: A Practical Guide

    This article breaks down the engine architecture behind a 3D fighting game, focusing on why a polished main menu often fails to translate into a solid combat experience. It explains a reusable design that separates fixed-step logic from interpolated rendering, drives characters with state machines and frame data, handles local two-player input, builds three-tier AI, and manages hit detection, throws, energy, super moves, cinematics, pause, and best-of-three match flow. Game developers will find concrete structures, pseudocode, and engineering practices for keeping combat deterministic, debuggable, and fair.

    1. Problem Background and Goals

    The source material describes a 3D fighting game with a two-character versus setup: a home screen with two independent characters and a rainy rooftop stage. Once a match starts, it supports single-player against AI (easy, standard, and hard), local two-player versus, character selection, best-of-three rounds, and mechanics such as blocking, throws, jumping, dashing, juggling, combo cancels, directional command specials, full-meter super moves with close-up cinematics, pause, and win/loss results. It also points out a common pain point: the home screen and character showcases look great, but the experience drops noticeably once the fight begins.

    This “great presentation, weak combat” pattern is widespread in fighting game development. The root cause is usually not art but insufficient determinism in the combat core. This article abstracts it into a general engineering problem: how to use a reusable architecture to connect character presentation, input, hit detection, AI, camera, and match flow into a stable, debuggable pipeline. The goals are:

    • Decouple combat logic from rendering so the same input produces the same result.
    • Drive character behavior with a state machine plus frame data so designers can tune values easily.
    • Keep AI tiers controllable and behavior explainable.
    • Support conflict-free local two-player input, best-of-three rounds, and pause/resume.
    • Keep the presentation layer (close-ups, camera) from polluting the logic layer.

    2. Overall Architecture: Separating Logic from Presentation

    Use a “fixed-step logic plus interpolated rendering” structure. Logic advances at a fixed rate (for example, 60Hz), while rendering runs at a variable frame rate and only reads logic snapshots for interpolation. This keeps hit detection stable, replays consistent, and AI decisions reproducible.

    1. Input sampling -> Character state machine -> Frame data advance -> Collision and detection -> Energy/timer -> Event queue -> Presentation layer (animation/camera/effects)

    Key conventions:

    • The logic layer does not depend on the render frame; all time is measured in “logic frames.”
    • Character position and velocity use fixed-point or fixed-precision floats to reduce cross-platform differences.
    • Hits, blocks, successful throws, and similar events are broadcast as events that the presentation layer subscribes to.
    • Randomness uses a seedable pseudo-random source so AI and effects are reproducible.

    3. Characters and Frame Data: The Foundation of Combat Feel

    Each character consists of three parts: skeleton/mesh, state machine, and frame table. The frame table describes each move’s startup frames, active frames, recovery frames, cancel windows, and displacement.

    Example frame table structure:

    1. MOVE = {
    2. "stand": {"startup": 3, "active": 2, "recovery": 6, "cancel_from": 5},
    3. "crouch": {"startup": 2, "active": 2, "recovery": 5},
    4. "jump": {"startup": 4, "air": True},
    5. "dash": {"startup": 5, "move": (6.0, 0.0)},
    6. "throw": {"startup": 7, "range": 1.2, "unblockable": True},
    7. "special": {"startup": 8, "cost": 0, "projectile": False},
    8. "super": {"startup": 10, "cost": 100, "cinematic": True},
    9. }

    The state machine should include: idle, forward/backward movement, crouch, jump (with air control), dash, block (standing/crouching), hitstun, juggle, knockdown and wake-up, throw, special, super, and guard-break stun. Each state defines its “interruptible window.” Combo cancels are implemented by switching to an allowed move during a specific window in the active or recovery frames.

    Key points for juggles and combos:

    • On hit, give the target vertical velocity and put it into a juggle state where gravity keeps acting.
    • During juggle, hits do not cause landing, enabling air combos.
    • Each hit reduces “hitstun decay” to prevent infinite combos.
    • Combo count and damage scaling factors feed into the final result, rewarding strategy over mindless strings.

    4. Input and Local Two-Player: Avoiding Key Conflicts and Drift

    The biggest risk in local two-player is keyboard hardware conflict and dropped input. Recommendations:

    • The logic layer only consumes “abstract commands” (left/right/up/down/attack/block/throw), converted by an input mapping layer.
    • The two mappings do not overlap, and the settings screen allows rebinding.
    • For directional command specials, use an “input buffer plus directional history window,” for example recording the last N frames of direction sequences and matching patterns like “down, down-forward, forward+attack.”
    • For dashes, use double-tap direction or direction+button to avoid conflict with walking.
    • Align input sampling with logic frames to prevent sampling jitter on high-refresh displays.
    1. Direction history ring buffer (length = 12 frames)
    2. Matcher: subsequence matching + time window constraint + priority (super > special > normal)

    5. Three AI Tiers: From “Moving” to “Calculating”

    AI should not be a “hand-speed cheat” but a machine with limited states and decisions. The three tiers differ in reaction delay, decision frequency, block probability, and combo complexity:

    • Easy: low block rate, few combos, long decision intervals.
    • Standard: blocks and counterattacks, can perform basic juggle combos.
    • Hard: reads commands, pre-inputs, controls distance, and chooses the optimal wake-up after being hit.

    Implementation uses a three-stage “perceive-decide-execute” flow:

    1. def ai_tick(self, state, frame):
    2. if frame % self.decision_interval != 0:
    3. return self.current_plan
    4. dist = abs(self.opponent.x - self.x)
    5. if self.opponent.is_attacking and self.rng() < self.block_rate:
    6. return Plan("defend")
    7. if dist < 1.5 and self.can_throw():
    8. return Plan("throw")
    9. if dist > 3.0:
    10. return Plan("approach")
    11. return Plan("poke")

    Key point: AI outputs abstract commands with the same structure as player input and is bound by the same frame data and cooldowns, ensuring fairness and debuggability. The random source can be seeded to reproduce issues.

    6. Hit Detection, Blocking, and Throws

    Use capsule/box approximations for hit detection, split into attack boxes and hurt boxes, tested for overlap each frame. Blocking must distinguish standing/crouching block and guard breaks (such as low attacks, air attacks, and unblockable throws). Throws start at close range; on hit, both characters enter an uninterruptible throw animation, then return to neutral.

    Pseudocode:

    1. for each attacker in fighters:
    2. if attacker.state in ACTIVE_FRAMES:
    3. for each target in opponents:
    4. if overlap(attacker.hitbox, target.hurtbox):
    5. if target.is_invulnerable(): continue
    6. if is_throw(attacker.move) and target.can_be_thrown():
    7. emit THROW_HIT
    8. elif target.is_blocking() and not move.unblockable:
    9. emit BLOCK; apply_chip_damage()
    10. else:
    11. emit HIT; apply_hitstun(); apply_knockback()

    7. Energy, Super Moves, and Close-Up Cinematics

    The energy meter grows over time and through offense and defense. At full meter, a super move can be released. The key to supers is not damage but “aligning presentation time with logic time”: entering a close-up may briefly slow or pause logic, but state must remain consistent after resuming.

    • The close-up camera is triggered by the presentation layer subscribing to the “super start” event.
    • The logic layer records “remaining cinematic frames” and resumes normal advancement after the cinematic ends.
    • Camera switches only interpolate and do not change character coordinates.
    • To protect competitive fairness, provide an option to disable close-ups.

    8. Flow, Pause, and Best-of-Three Results

    Use an explicit state machine for match flow: home -> character select -> stage load -> round start -> fighting -> round end -> next round/match end -> results. Pause is not simply stopping rendering; it freezes the logic clock and records the input buffer, then clears easily misinterpreted commands on resume to avoid “instant move on resume.”

    Best-of-three key points:

    • Each round has independent timing, and the energy reset policy must be defined (commonly, partial energy carries between rounds).
    • Draw handling (double KO) must define a rematch or health comparison.
    • Result data includes remaining time, max combo, and total damage for review.

    9. Performance and Maintainability Recommendations

    • Split logic and rendering into separate threads or modules, with render interpolation reading snapshots.
    • Externalize frame data and AI parameters as configuration so designers can hot-tune.
    • Build an “input replay” mechanism; a fixed seed can reproduce an entire match.
    • Use logging services and monitoring alerts to track frame time, detection anomalies, and crash rate.
    • Store assets and configuration in object storage, and use a container platform for canary releases.

    10. Conclusion

    The essence of a fighting game that “breaks once you start playing” is treating presentation as the core. The correct order is: first define logic frames and frame data, then input and hit detection, then AI and flow, and only then polish camera and effects. Following this ten-layer structure preserves feel and fairness while carrying the home screen’s polish into every match.