Browser-Based 3D Fighting Game Architecture: Technical Implementation and Design Breakdown

    This article breaks down the technical architecture behind a browser-based 3D fighting game, using a reference build with two characters, a rainy rooftop stage, three AI difficulty levels, local two-player versus, and a best-of-three format. It explains why polished landing pages often degrade once combat begins, then covers the four-layer logic/presentation split, fixed-timestep updates with interpolated rendering, asset pipelines with explicit frame data, finite-state-machine combat and hitbox resolution, perception-decision-execution AI design, local synchronization and input buffering, camera and match-flow handling, performance budgets, and observability and testing practices. The goal is a stable, playable prototype that can be iterated with new characters and stages.

    Browser-Based 3D Fighting Game Architecture: Technical Implementation and Design Breakdown

    As AI-assisted programming becomes more common, a familiar pattern appears: the generated landing page and character showcase look impressive, but the experience degrades quickly once actual combat starts. This is not a limitation of the tools. Fighting games belong to the most complex category of real-time interactive systems. Using a 3D fighting game with two characters, a rainy rooftop stage, three AI difficulty levels, local two-player versus, and a best-of-three format as a reference, this article abstracts the general technical problems and presents a complete architecture design with key implementation points.

    1. Why “Great Landing Page, Broken Gameplay” Is Inevitable

    The landing page and character showcase are static or quasi-static rendering: there are no hard real-time constraints, so they can tolerate high polygon counts, post-processing effects, and pre-baked lighting. The combat phase is a hard real-time system, typically requiring a stable 60 FPS, which means a per-frame budget of about 16.6 milliseconds, with logic and rendering strictly decoupled.

    The root causes of degraded experience usually fall into four areas:

    1. Logic frame rate is coupled to render frame rate, so dropped frames directly cause hit-detection drift;
    2. Combat state is maintained through scattered boolean variables, producing contradictory states such as “simultaneously hit and attacking”;
    3. Attack detection depends on animation playback progress, so hitboxes become misaligned after animation blending and retargeting;
    4. The character controller reuses a generic third-person approach, lacking fighting-specific lock-on, ground snapping, and hit-reaction displacement handling.

    2. Overall Architecture: Separating Logic from Presentation

    A four-layer structure is recommended, with layers communicating only through data and events:

    • Input layer: Collects keyboard or gamepad input and normalizes it into abstract “direction + button” commands, hiding device differences.
    • Logic layer: Advances at a fixed timestep (1/60 second recommended), handling the state machine, displacement, collision, hit resolution, and resource management, without touching any render objects.
    • Presentation layer: Reads logic-layer snapshots to drive skeletal animation, effects, camera, and audio.
    • Resource and platform layer: Handles loading and caching of models, textures, and audio, plus render context and lifecycle management.

    Illustrative code:

    1. const STEP = 1 / 60;
    2. let acc = 0;
    3. function frame(now) {
    4. const dt = Math.min((now - last) / 1000, 0.25); // Prevent large jumps after tab switch
    5. last = now;
    6. acc += dt;
    7. while (acc >= STEP) {
    8. input.sample(); // Sample and encode commands
    9. logic.step(STEP); // Advance at a fixed timestep
    10. acc -= STEP;
    11. }
    12. render(logic.snapshot(), acc / STEP); // Interpolated rendering to remove jitter
    13. requestAnimationFrame(frame);
    14. }

    A fixed timestep combined with interpolated rendering is the foundation for consistent hit detection and smooth visuals.

    3. Character and Scene Asset Pipeline

    The asset requirements for 3D fighting games differ from open-world games; the core is control and reusability:

    • Unified skeleton and naming conventions, allowing animation retargeting split into “lower-body movement + upper-body action”;
    • Each move animation carries structured metadata: startup frames, active hit window, recovery frames, and cancel windows;
    • Modular scene assembly; environments like a rainy rooftop need clear walkable-area boundaries and a camera occlusion strategy;
    • Materials and lighting constrained by a performance budget, with rain, fog, and reflections controlled by tiered toggles and automatic downgrade on low-end devices.

    The key practice is to explicitly export “hit data” from art assets rather than making code guess animation progress.

    4. Combat System: State Machine and Hit Resolution

    Character behavior should be modeled as a finite state machine, with states covering at least: idle, walk, jump, crouch, guard, attack, hit, airborne, knockdown, wake-up, throw, and being thrown.

    1. const State = { IDLE:'idle', WALK:'walk', CROUCH:'crouch',
    2. GUARD:'guard', ATTACK:'attack', HIT:'hit',
    3. AIR:'air', KNOCKDOWN:'down', THROW:'throw' };

    Hit detection uses attack boxes and hurt boxes intersected within a logic frame, rather than relying on model triangles. Key points include:

    • Attack boxes activate only during the active window declared in metadata;
    • On hit, the flow enters “hit confirmation,” checking whether a cancel is allowed and whether launch is triggered;
    • Guard distinguishes standing block from crouching block, and throws cannot be blocked by ordinary guard, forming a rock-paper-scissors dynamic;
    • Dashes and jumps require ground snapping to prevent characters from sinking into the floor or hovering with jitter;
    • Combo cancels depend on a “cancel window + target state whitelist,” with anything outside the whitelist rejected.

    Hit displacement, screen shake, and hit-stop are presentation-layer feedback and must never modify logic detection in reverse.

    5. AI Design: What Actually Differs Across Three Difficulty Levels

    Difficulty differences should not appear as stat inflation, but as differences in decision quality and reaction characteristics. A three-stage “perceive-decide-execute” approach is recommended:

    1. Perceive: Track features such as distance, opponent state, energy, and whether the opponent is in punishable recovery;
    2. Decide: Select behavior via weighted scoring over a finite state set, optionally organized with a behavior tree;
    3. Execute: Convert decisions into virtual input isomorphic to the player’s, obeying the same frame-data constraints.
    1. function decide(self, foe) {
    2. const d = Math.abs(self.x - foe.x);
    3. if (foe.isPunishable()) return 'combo_punish';
    4. if (d > 2.5) return 'dash_in';
    5. if (d < 1.2) return Math.random() < self.aggression ? 'attack' : 'guard';
    6. return 'approach';
    7. }
    • Easy: High reaction delay, high decision noise, almost never guards proactively;
    • Normal: Guards and counters, with moderate combo success rate;
    • Hard: Faster reactions, better at punishing recovery, more sensible energy management.

    Letting the AI use the same input channel as the player avoids the unbalanced feeling of “AI frame-data cheating.”

    6. Local Two-Player Versus and Synchronization

    Local two-player mode shares the same logic clock, which is relatively simple to implement, but input timing must be solved:

    • Both players’ commands are sampled together and resolved together within the same logic frame to ensure fairness;
    • Use an input buffer (typically 3 to 6 frames) to absorb sampling jitter;
    • The character select phase is separated into a menu state machine so it does not pollute the combat state;
    • If later extended to remote versus, this structure can be reused by adding input delay and snapshot synchronization.

    7. Camera, Settlement, and Flow Closure

    • When supers and super arts trigger a close-up camera, logic keeps advancing and the camera only interpolates the transition, avoiding the hidden advantage of “invincible while the animation plays”;
    • The energy bar accumulates from both taking and landing hits, and super arts are allowed only at full energy;
    • Best-of-three is maintained by a match manager tracking score and round state, with settlement covering draws and simultaneous knockdowns;
    • Pause must freeze the logic clock rather than only stopping rendering, and the accumulator must be reset on resume to prevent time jumps.

    8. Performance Budget and Common Pitfalls

    Concern Recommended approach
    Frame budget Separate logic and rendering; fixed logic timestep
    Memory Tiered texture loading; release scene resources promptly
    Hit detection Box intersection; avoid per-triangle checks
    Debugging Visualize hitboxes, state, and frame-data panels
    Downgrade Disable reflections and post-processing; lower shadow precision

    9. Observability and Testing

    Fighting games have high regression costs, so three capabilities are recommended: frame-data table-driven tuning for designers; recorded input sequences for replay to reproduce defects; and exhaustive unit tests over the state machine covering cancels, throw breaks, simultaneous hits, and timeout decisions. If deployed in the cloud, container platforms can host build and replay tasks, logging services and monitoring alerts can track abnormal frame rates and crash rates, and object storage can hold replay files.

    10. Conclusion

    The gap from “stunning landing page” to “playable match” lies not in art but in systems engineering: a fixed-timestep logic core, an asset pipeline with explicit frame data, state-machine-driven combat resolution, AI using an isomorphic input channel, and rigorous flow and settlement management. Support from Baidu AI Cloud in general compute, containers, and observability can make building, testing, and operating such real-time interactive projects smoother. Implementing the layers above step by step yields a stable, playable combat experience at the prototype stage, after which characters and stage content can be iterated.