3D Fighting Game Engine Architecture: A Practical Guide to Decoupling Combat and Presentation

    This guide explains how to structure a 3D fighting game engine so that combat logic stays stable under real matches instead of only looking good in a menu demo. It covers a five-layer architecture, data-driven character differentiation, layered hitbox/hurtbox/pushbox collision with frame data, state-machine combos and cancel windows, explainable three-tier AI, stage and camera implementation, local two-player best-of-three flow, and a verification checklist for deterministic replay and balance testing.

    1. The Problem: Why Menu Demos Look Great but Actual Fights Fall Apart

    In most 3D fighting game prototypes, developers spend roughly 80% of their effort on the main menu and character showcase, because that work produces immediate visual feedback. Once an actual match starts, the problems arrive all at once: stiff character motion, inaccurate hit detection, camera clipping through walls, and robotic AI behavior. The root cause is usually not art quality. It is that the combat layer and the presentation layer are not decoupled: animation state, logic state, and collision volumes all share one data set, so any single change triggers a chain of failures.

    This guide uses a warship as an analogy for a heavy combat platform. Treat the engine as the ship: the engine room is the main loop, fire control is the hit detection system, radar is AI perception, and the bridge is input and camera scheduling. Each compartment has a single responsibility and communicates through explicit interfaces, which is what keeps the whole system stable under high-pressure matches.

    2. Layered Architecture

    A five-layer structure works well. Dependencies point downward only; reverse calls are forbidden:

    1. Presentation layer (animation/VFX/camera/audio)
    2. ↑ read-only snapshot
    3. Logic layer (state machine/hit detection/energy/timers)
    4. ↑ commands
    5. Input layer (local two-player/AI decisions)
    6. ↑
    7. Platform layer (rendering/physics/assets/logging)

    The key constraint: the presentation layer must never modify logic-layer data. It renders by interpolating a “logic frame snapshot.” That way, when frames drop, logic still advances at a fixed step and hit detection does not drift.

    3. Character System: Differentiated Design for Two Characters

    Two independent characters should share the same state machine skeleton and be differentiated through configuration tables, not two separate code paths.

    • Attribute config: HP, walk speed, gravity coefficient, hitstun multiplier, energy gain rate.
    • Move set: idle, forward/back walk, crouch block, jump, dash, hit reaction, air hit, knockdown, throw startup, special move startup.
    • Derived rules: gravity and cancel windows while airborne; whether a dash can be interrupted by an attack.

    Example configuration structure:

    1. CHARACTER = {
    2. "id": "char_a",
    3. "hp": 1000,
    4. "walk_speed": 3.2,
    5. "gravity": -22.0,
    6. "energy_gain": 0.8,
    7. "cancel_window": {"normal": 8, "special": 12}, # unit: logic frames
    8. }

    Differentiation comes from tuning numbers and trimming the move set. Character A excels at mid-range pressure with a longer dash distance; Character B has longer throw range but shorter hang time on jumps. Balance stays adjustable and branch code does not balloon.

    4. Combat Hit Detection: Layered Collision and Frame Data

    Hit detection in a 3D fighter must be layered. Use at least three volume types:

    1. hurtbox: follows the skeleton, changes with the animation, compresses in height while crouch blocking.
    2. hitbox: enabled only during the “active frames” of an attack.
    3. pushbox: prevents the two characters from fully overlapping and keeps close-range spacing stable.

    Record structured frame data every frame for debugging and balancing:

    1. Move: forward heavy punch
    2. Startup: 6 | Active: 3 | Recovery: 12
    3. hitbox offset: (0.6, 1.2, 0) radius 0.35
    4. On hit: hitstun 18 frames, knockback 2.0, cancelable into special

    Defense must distinguish standing block / crouch block / air block, and it needs direction-based guard detection: the player’s stick direction determines the guard stance, not the button itself. Throws require “close range + facing the opponent + neither side in hitstun”; on success, the match enters a throw sequence that normal attacks cannot interrupt.

    5. Combos and Cancels: A State-Machine-Driven System

    A combo is fundamentally “cancel window + legal state transition.” A finite state machine with frame windows is the recommended approach:

    1. def try_cancel(state, frame, target):
    2. if state.phase != "active" and state.phase != "recovery":
    3. return False
    4. if frame > state.cancel_until:
    5. return False
    6. return target in state.cancel_targets

    Air combos need an extra “air hit counter” that reduces the remaining actionable frames on each hit; when it reaches zero, the character is forced to land, which prevents infinite combos. When energy is full, a super move is allowed and triggers a cinematic camera: logic pauses for 0.5 seconds while only the presentation layer plays the camera move, and the logic layer marks a “sequence lock” so hit detection does not go out of sync.

    6. AI Design: Explainable Three-Tier Difficulty

    AI should not be “stat cheating.” It should be a difference in decision quality. A finite state machine plus utility scoring is a practical base:

    • Easy: 12-frame reaction delay, 30% block probability, no proactive cancels, combos limited to one hit.
    • Normal: 6-frame delay, 60% block probability, uses two-hit combos and occasional throws.
    • Hard: 3-frame delay, 85% block probability, recognizes the opponent’s moves and pre-inputs guard, executes full combos.
    1. utility = w1*spacing gain + w2*opponent hitstun + w3*own energy - w4*risk

    Weights shift with difficulty; Hard raises the “risk” weight to avoid mindless offense. All tiers share the same move-legality validation, so the AI can never perform an action a player cannot execute.

    7. Stage and Camera: Engineering a Rainy Rooftop

    For a rainy night scene, the goal is a reusable atmosphere pipeline rather than a pile of effects: reflective ground uses planar reflection plus a roughness map; rain streaks use GPU particles bound to camera depth; neon signs mix a few dynamic lights with baked lighting. The camera needs three modes: default side view, super move close-up, and a win/lose orbit shot. The camera must implement collision avoidance, using ray casts to keep it from entering walls.

    8. Local Two-Player and Best-of-Three Flow

    The input layer uses an “input buffer” that stores the last 8 frames of directional input and recognizes directional special move motions (for example, down, down-forward, forward + punch). When two players share one keyboard, add key conflict detection and input debouncing. The match format is a simple loop:

    1. best_of(3): first to 2 round wins takes the match
    2. each round: 3-2-1 countdown → fight → KO sequence → results

    Pausing must freeze both the logic frame counter and the audio clock; on resume, reset the input buffer so a special move is not accidentally triggered the instant play continues.

    9. Common Pitfalls and Acceptance Checklist

    • Logic and rendering frame rates are coupled, so a frame drop immediately breaks hit detection.
    • Hurtboxes do not update with the animation, causing damage when a hit visually misses.
    • No camera collision detection, so the camera clips through geometry.
    • AI difficulty is only doubled numbers, which feels bad and is unmaintainable.
    • The input buffer is too short, so directional special moves fail to trigger reliably.

    Recommended acceptance work: build a “frame data replay” tool that records inputs and the random seed for deterministic playback; run 100 automated matches per AI tier and track win rate and move distribution so balance is measurable. With these layers and checks in place, a 3D fighting prototype can move from a menu demo to a complete, tunable, extensible piece of engineering.