Browser-Based 3D Fighting Game Architecture: Decoupling Combat Logic from Rendering

    This article walks through a practical architecture for building a 3D fighting game that runs in the browser. It explains why deterministic combat logic matters more than visual fidelity, how to split the codebase into core, input, AI, render, and UI modules, and how to fix the common "great on the home page, degraded in the match" problem with tiered asset loading. It also covers the fixed-timestep game loop, frame-data move tables, hitbox and hurtbox detection, state transitions for blocking, throws, juggles and cancels, motion-input recognition with input buffering, three-tier AI difficulty built on virtual inputs, local versus play and match flow, plus performance and testing practices.

    1. Why the Browser Is a Viable Platform for a 3D Fighting Game

    Traditional fighting games have long depended on dedicated runtimes and locally installed packages. Browsers, with no installation required, cross-device support, and easy distribution, are becoming an important platform for lightweight interactive entertainment. The hard part of building something that genuinely feels like a fighting game in a browser is not the visuals — it is deterministic combat logic: stable frame pacing, reproducible hit detection, and replayable input. So the first principle of the architecture is to fully decouple logic from rendering.

    A recommended module layout:

    1. core/ # Pure logic: state machines, hit detection, round rules (no rendering dependency)
    2. input/ # Input capture and command recognition (keyboard/gamepad abstraction layer)
    3. ai/ # Decision layer, outputs virtual input only
    4. render/ # Scene, characters, camera, effects
    5. ui/ # Menus, character select, pause, results

    As long as both AI and human players connect through the same “virtual input” interface, behavior stays consistent, testing stays simple, and recording replays later becomes straightforward.

    2. Characters and Stages: From Home Page Showcase to In-Match Presentation

    The core complaint in the original feedback was that “the character looks stunning on the home page but clearly drops a level once the match starts.” This is usually not an art problem but a missing tiered asset loading strategy: the home page only needs a high-precision static display, while a match requires skeletal animation, multiple animation sets, and real-time shadows all active at once.

    Practical recommendations:

    • Use a high-poly model with a slow orbiting camera on the home page, keeping first-screen assets small;
    • Prefetch assets and use a transition mask before entering a match, avoiding stuttering loads during combat;
    • Use medium-precision models with skeletal animation in matches, reducing overhead through texture compression and geometry merging;
    • Build atmosphere on the stage (for example, a rainy rooftop) with a few dynamic elements: reflective ground, volumetric light, light rain particles, and allow these to be disabled on low-end devices.

    Two differentiated characters should cover at least this animation set: idle stance, walking, jumping, crouching, taking a hit, knockdown, throws, special move startup and hit, and a victory pose. The number of animations often affects how authentic the game feels more than model precision does.

    3. Combat Core: State Machines, Frame Data, and Hit Detection

    The “feel” of a fighting game is essentially precise management of frame data. Use a fixed-timestep logic loop with interpolated rendering:

    1. const FPS = 60;
    2. let acc = 0, last = performance.now();
    3. function loop(now){
    4. acc += now - last; last = now;
    5. while (acc >= 1000 / FPS) {
    6. step(); // logic frame: advance state machines and hit detection
    7. acc -= 1000 / FPS;
    8. }
    9. render(acc / (1000 / FPS)); // interpolated rendering
    10. requestAnimationFrame(loop);
    11. }

    Describe each move in frames, forming a readable “move list”:

    1. const moves = {
    2. punch: { startup: 4, active: 3, recovery: 8, damage: 60,
    3. hitbox: {x: 0.6, y: 1.2, w: 0.9, h: 0.4}, cancelable: true },
    4. uppercut: { startup: 5, active: 4, recovery: 22, damage: 110,
    5. launch: true, cancelable: false }
    6. };

    Use rectangular or capsule bounding boxes for hit detection, checking each frame whether the attack box intersects the hurtbox, and resolving damage only once during the same active phase to avoid repeated damage across multiple frames. After being hit, a character enters hitstun frames during which no action is possible — this is where the sense of impact comes from.

    Blocking, throws, juggling, and combo cancels can all be modeled as state transition rules:

    • Block: the hit connects but damage is heavily reduced, entering blockstun with a counterattack window;
    • Throw: short range, cannot be blocked normally, transitions into a cinematic state on hit;
    • Juggle: after being hit, the character enters an airborne hit state with limited gravity and limited ability to act;
    • Cancel: after the hit-confirm frame, a higher-priority move may interrupt the current recovery frames, forming a combo.

    4. Command Recognition and Input Buffering

    Directional special moves need a “command recognizer” rather than frame-by-frame exact matching. A common approach maps directional input to a sequence of 8-way symbols, combined with a time window and longest common subsequence matching:

    1. function match(buffer, pattern, window = 12) {
    2. const recent = buffer.slice(-window).map(i => i.dir);
    3. return containsSubsequence(recent, pattern); // e.g. [down, down-right, right, punch]
    4. }

    Also add an input buffer queue (typically 6–10 frames) so that inputs entered early during recovery frames are still consumed correctly — this is the key to responsive controls. The energy gauge, the super move at full energy, and the close-up camera work as a separate layer of assets and presentation: during a close-up you can briefly adjust camera focal length and time scale, but logic frames must either keep advancing or pause explicitly, to avoid inconsistent state.

    5. Tiered AI Difficulty: From Random to Strategic

    Three difficulty tiers should not be mere numeric scaling but increasing complexity in the decision layer:

    1. Easy: mostly approaching and random attacks, large reaction delay, almost never blocks on its own;
    2. Standard: spacing control, combos after hit confirmation, probabilistic blocking when pressured;
    3. Hard: reads the player’s input habits, predicts startup moves to counter, manages energy and resources, actively sets up juggles.

    Implementation can use a “finite state machine + decision interval + weight table,” letting the AI produce only virtual input so it shares all combat logic with human players:

    1. function decide(self, foe, level) {
    2. const dist = Math.abs(self.x - foe.x);
    3. const table = level === 'hard'
    4. ? [{ a: 'throw', w: dist < 1 ? 5 : 0 }, { a: 'block', w: foe.busy ? 4 : 1 }]
    5. : [{ a: 'approach', w: 3 }, { a: 'punch', w: dist < 1.2 ? 2 : 0 }];
    6. return weightedPick(table);
    7. }

    6. Local Two-Player, Rounds, and Match Flow

    Local versus play needs to solve input conflicts and focus issues: bind separate keys for each player or use gamepad mappings, and auto-pause when the window loses focus. Round rules are best kept in a dedicated “match controller” responsible for best-of-three, draw handling, pause, win/loss resolution, and restarts. The UI should only subscribe to events rather than modify state directly.

    7. Performance and Engineering

    • Rendering: control draw batches, merge static geometry, scale particle counts by device tier;
    • Memory: load move and stage assets in chunks, releasing them during transitions;
    • Stability: with logic separated from rendering, core combat logic can be unit tested without rendering, covering combos, blocking, and throw edge cases;
    • Observability: hook into a general-purpose logging service and monitoring/alerting categories, collecting frame rate, load times, and exceptions to make production issues easier to locate; static assets can be served through object storage and a content delivery network to improve first-screen speed.

    8. Conclusion

    What separates a good 3D fighting game from a poor one is not model precision but rigor in frame data, input responsiveness, and the depth of AI decisions. Proceed in the order of “logic core — input layer — AI layer — presentation layer”: make combat correct first, then make the visuals shine. That is how you avoid the familiar gap between a stunning home page and a broken match.