3D Fighting Game Engine Architecture and In-Game Implementation

    This article breaks down how to build a maintainable and responsive 3D fighting game core, using a rainy rooftop stage and two-character front end as the starting point. It explains a three-layer architecture that separates presentation, logic, and data; a fixed-timestep loop with explicit frame data and a per-character state machine; input buffering, guarding, and throw resolution; juggle, combo, and cancel rules; three AI difficulty tiers based on decision quality rather than inflated stats; and best-of-three match flow with pause and settlement handling. A troubleshooting checklist covers the most common causes of in-game feel collapse.

    1. Problem Background and Goal Breakdown

    The source material describes a 3D anime-style fighting game: the home screen features two independent characters (Yin Shilin and Jiang Yina) against a rainy rooftop stage, and both look strong. The experience drops noticeably once a match starts. This pattern is very typical in 3D fighting game development: the presentation layer (home screen, character select, stage atmosphere) can raise perceived quality quickly through art and camera work, while in-match combat depends on tight coupling between hit detection, state, and feedback. Any timing or numeric mistake there breaks the feel immediately.

    So this article does not revolve around any specific AI coding tool or third-party product. Instead, it abstracts the problem into a general engineering question: how to build a maintainable, extensible 3D fighting core with stable feel and clear module boundaries. The goals are:

    • Decouple character and stage presentation in the home and select phases from in-match logic;
    • Single player versus AI with easy, normal, and hard tiers;
    • Local two-player matches, character selection, and best-of-three format;
    • Guard, throws, jumps, dashes, juggles, and combo cancels;
    • Direction-based special moves, full-meter super moves, and close-up cameras;
    • Pause, win/loss settlement, and data cleanup.

    2. Overall Layered Architecture

    Use a “presentation - logic - data” split so animation, effects, and hit detection are not written together.

    1. Presentation layer: character models, skeletal animation, stage (such as the rainy rooftop), camera and effects, UI.
    2. Logic layer: fixed-step simulation, state machine, input buffer, hitboxes, AI decisions, match flow.
    3. Data layer: character attribute tables, move frame data, AI parameters, input mapping config.

    The key principle is decoupling logic from frame rate: rendering frame rate can vary, while logic advances at a fixed step (for example 60Hz), keeping feel consistent across devices.

    1. Home/Select (presentation) --> Match load (data) --> Fixed-step loop (logic)
    2. |-- Input sampling (local 2P / AI)
    3. |-- State machine advance
    4. |-- Hit detection and resolution
    5. |-- Meter / match flow / pause
    6. +--> Interpolated rendering (presentation)

    3. Home and Select: Separating “Looks Good” from “Plays Well”

    The two characters and the rainy stage look good because they are low-coupling presentation logic: camera paths, idle animations, weather, and lighting are all predictable. The in-match drop usually happens because the high bar set by the presentation layer gets carried into the logic layer, which lacks frame data to support it.

    Practical advice:

    • The select screen only produces a “selection result”: write the character ID into the match config, and do not pre-run combat logic during selection;
    • Stage atmosphere (rain, reflections, fog) is implemented with presentation-layer particles and post-processing and does not participate in hit detection;
    • Character idle and victory close-ups use separate animation states so they never mix with the combat state machine.

    4. Fixed Step and the Character State Machine

    The core of a fighting game is the state machine. At any logic frame, each character is in exactly one explicit state: idle, walk, jump, dash, guard, hitstun, air, knockdown, throw, special, and so on.

    1. enum class State { Idle, Walk, Jump, Dash, Guard, Hitstun, Air, Knockdown, Throw, Special };
    2. struct FrameData {
    3. int startup; // startup frames
    4. int active; // active duration
    5. int recovery; // recovery frames
    6. bool cancelable; // whether it can be canceled
    7. };
    8. void step(Fighter& f, const Input& in) {
    9. f.buffer.push(in); // input buffer
    10. if (f.state == State::Hitstun || f.state == State::Air) { f.applyPhysics(); return; }
    11. if (auto cmd = f.buffer.match(f.frameData)) { f.start(*cmd); }
    12. f.advanceFrame(); // advance frame counter and state
    13. }

    Key points:

    • Every move has startup, active, and recovery frame data; hit and guard detection only apply during the active window;
    • During hitstun and juggle, active input is disallowed; only physics and stun decay run;
    • State transitions must declare cancel windows explicitly, otherwise “combo cancels” become cancel-anytime.

    5. Input, Guard, and Throws

    Local two-player play needs stable input sampling and buffering. Keep a separate input mapping and a short buffer queue (for example 8-12 frames) per player to absorb key jitter and simultaneous presses.

    • Guard: split into standing and crouching guard; entering guard requires the right timing of “back / down-back plus being hit”; guard has stun and a guard-crush value so infinite turtling is not possible.
    • Throws: a throw is a close-range hit that normal guard cannot block, usually with startup frames and a distance threshold; if the defender enters hitstun before the throw’s startup frame, the throw whiffs.
    • Dash and jump: dash provides movement and a cancel option; jump changes the hurtbox height and must be distinguished from the juggle state.
    1. if (hit.type == Throw && dist < throwRange && defender.state != Hitstun) -> throwSuccess
    2. else if (defender.isGuarding() && hit.blockable) -> onGuard
    3. else -> onHit

    6. Juggles, Combos, and Cancel Rules

    Juggles and combo cancels are the dividing line for feel. Constrain them with three things together: a hit counter, remaining cancel budget, and stun decay.

    • On hit, the character enters a juggle; gravity and damping determine the fall curve;
    • Each hit in a combo shortens subsequent stun (decay) to prevent infinite combos;
    • Cancels only work inside the move’s cancelable window and consume one cancel credit;
    • A super move usually requires a full meter, empties the meter, and enters a close-up camera state.
    1. onHit:
    2. comboCount += 1
    3. hitstun = baseHitstun * decay(comboCount)
    4. if (move.cancelable && cancelBudget > 0 && now in cancelWindow) allowCancel()

    7. Three AI Difficulty Tiers

    AI should not be “double the numbers”; it should differ in decision quality and reaction frames:

    • Easy: large reaction delay, low guard probability, rarely uses specials, short combos;
    • Normal: guards and interrupts, can complete basic combos, occasionally uses a super;
    • Hard: fast reactions, recognizes throws and dashes, longer combos, more aggressive meter management.

    Implementation uses three stages, “perceive - decide - execute”: the perception layer reads distance, opponent state, and meter; the decision layer picks behavior by difficulty weights; the execution layer maps behavior to the same inputs a player uses, so the AI never gets cheating-level information.

    8. Match Flow, Pause, and Settlement

    Best-of-three is a match flow state machine: select -> round start -> fight -> round end -> next round or match end. Pause must freeze logic stepping while keeping optional static rendering in the presentation layer; settlement must reclaim input buffers, meter, and combo counters to avoid cross-round contamination.

    1. Match: BestOf3
    2. onRoundEnd(winner): score[winner]++; if score==2 -> matchEnd else nextRound()
    3. pause: stop stepping logic; keep last frame; resume restores accumulator

    9. Common Feel-Collapse Points and Troubleshooting Checklist

    1. Hit detection out of sync with animation: check whether detection is placed on render frames instead of logic frames;
    2. Unstable combos: verify cancel windows and stun decay parameters;
    3. Guard not working: confirm guard timing against hit resolution and the guard-crush value;
    4. AI “reads minds”: make sure the AI only reads visible state and never future input;
    5. Rhythm breaks after pause: reset the accumulator on resume so multiple frames are not caught up at once.

    10. Conclusion

    The hard part of a 3D fighting game is not the home screen or the stage; it is the in-match loop of “frame - detection - state - feedback.” Fully decoupling presentation from logic, then applying a fixed step, explicit frame data, constrained cancels, and a three-tier decision AI, is what makes the in-game experience match the first impression of the home screen.