Building a Browser-Based 3D Fighting Game: A Practical Development Guide
This article walks through the technical design behind a browser-based 3D fighting game featuring two fully modeled characters, a rainy rooftop stage, single-player AI battles, and local two-player mode. It breaks down the core systems—state machines, frame data, input buffering, AI decision-making, energy mechanics, and round management—then addresses the common gap between polished showcase pages and underwhelming in-game feel, with concrete optimization paths for hand-feel, hit detection, performance, and balance.
Building a Browser-Based 3D Fighting Game: A Practical Development Guide
As web graphics technologies have matured, running a full-featured 3D fighting game in the browser is no longer a thought experiment. With general-purpose LLM-assisted coding tools, developers can even prototype the entire experience—from a character showcase homepage to a playable match—in a relatively short time. Using a typical project as an example—a 3D anime-style fighting game with two independently modeled characters, a rainy rooftop stage, single-player versus AI, and local two-player mode—this article systematically breaks down the technical design and implementation details behind it, and discusses the quality gaps common in prototypes and how to fix them.
1. Overall Architecture: From Showcase Page to Playable Match
A fighting game prototype typically consists of two layers: the presentation layer and the battle layer. The presentation layer includes the title screen, character select, and result screens; the battle layer is where real-time rendering and logic computation happen. Many projects suffer from a “stunning homepage, disappointing gameplay” problem, and the root cause is that the engineering complexity of the two layers differs entirely: the presentation layer only needs a few animations and camera moves to look good, while the battle layer must handle state machines, collision detection, input processing, frame data, and a host of real-time logic.
A recommended module breakdown:
- Rendering layer: scene, character models, lighting, and post-processing. For a rainy rooftop stage, the atmosphere comes from a low color-temperature key light, rain particle sheets, reflective wet-floor materials, and distant neon city accents.
- Logic layer: a fixed-timestep update loop that decouples battle logic from render frame rate, preventing combo judgment drift when frames drop.
- Input layer: keyboard event capture, input buffering, and command parsing.
- AI layer: a decision state machine or behavior tree that drives the computer opponent.
- UI layer: health bars, energy meters, round markers, pause menu, and result panel.
2. Asset Pipeline for Characters and Stage
A two-character design is a smart way to control workload. The base animation set for each character includes: idle, walk, jump, dash, crouch, block, hit reaction, knockdown, get-up, several normal attack strings, throw, special move, and super move cinematic. Animations are connected with blended transitions, typically kept under 0.1 seconds, to keep controls feeling crisp.
Key implementation points for the rainy rooftop stage:
- Ambient occlusion and volumetric fog to create depth;
- Rain streaks rendered as camera-facing particle ribbons, plus small splash particles where drops hit the ground;
- Wet-floor reflections via planar reflection or a simplified screen-space reflection, falling back to a specular map when performance is limited;
- Boundary constraints: a fighting game arena is essentially a 2D plane with boundaries—lateral movement is limited, and the Z axis is locked or used only for visual offset.
3. Core of the Battle System: State Machines and Frame Data
Fighting game character behavior is best modeled with a finite state machine. Each state defines three phases of frame data: startup, active frames, and recovery. A light punch, for example, might be: 5 startup frames, 3 active frames, 12 recovery frames. The essence of combo canceling is allowing an early jump from the active frames or hit-confirm of one state into the startup of a higher-priority move.
A simplified state definition:
const states = {idle: { cancelable: [], next: null },lightPunch:{ startup: 5, active: 3, recovery: 12,cancelable: ['heavyPunch', 'special'] },special: { startup: 12, active: 6, recovery: 28,cancelable: ['super'] },hitstun: { duration: 18, cancelable: [] },blockstun: { duration: 10, cancelable: [] }};
Juggles and combos rely on the height attribute of the hit state: when the opponent is airborne, a hit refreshes the juggle timer and applies a damage scaling factor. Damage scaling (e.g., multiplying each successive hit by 0.85) is the standard way to prevent infinite combos.
Blocking and throws form the classic counter triangle: attacks beat wake-up and movement, blocking beats attacks, and throws beat blocking. In implementation, the block state reduces damage to chip and applies blockstun; a throw must land at close range while the opponent is not in attack frames, and on hit both characters enter a locked cinematic.
4. Input Parsing: Motion-Input Specials
Motion inputs (e.g., down, down-forward, forward + punch) depend on an input buffer. The system maintains a rolling input history (typically 15–30 frames) and checks each frame whether the buffer tail matches a special move’s command sequence:
function matchCommand(buffer, pattern, window) {// pattern e.g. ['DOWN', 'DOWN_FORWARD', 'FORWARD', 'PUNCH']let idx = pattern.length - 1;for (let i = buffer.length - 1; i >= 0 && idx >= 0; i--) {if (buffer[i].frame < currentFrame - window) break;if (buffer[i].input === pattern[idx]) idx--;}return idx < 0;}
Two design points matter for feel: first, the input window should be lenient enough that players can execute moves reliably even at lower frame rates; second, directional inputs should be normalized so diagonal and cardinal directions can be matched fuzzily.
5. Three Difficulty Tiers for the AI Opponent
Single-player longevity depends on a clear difficulty gradient. A common approach is to use one decision framework and differentiate three tiers through parameters:
- Easy: long decision intervals (e.g., one decision every 45 frames), normals only, almost never blocks, no juggle follow-ups.
- Normal: decision intervals around 25 frames, uses specials, probabilistic blocking, and wake-up counterattacks.
- Hard: 10–15 frame decision intervals, adds controlled “reads” of player actions—punishing high-recovery moves, actively using throws to break turtling, and reliably confirming into supers when the meter is full.
In implementation, the AI observes distance, health difference, and the opponent’s current state every frame, then samples among behaviors like “approach / retreat / attack / block / jump” by weight. Hard AI needs random delay and an error rate on its reactions—otherwise it becomes a frustrating “perfect machine” and damages the sense of fairness.
6. Energy System and Super Move Cinematics
An energy meter driving super moves is the classic positive feedback loop of fighting games: both attacking and taking hits build meter, and a full meter unlocks a high-damage cinematic move. The close-up cinematic is a carefully choreographed camera state transition:
- On hit confirm, freeze both characters’ logic frames (hitstop, typically 3–8 frames);
- Push the camera from the default fighting angle to a close-up of the character’s face or weapon;
- Play the exclusive animation sequence with input locked;
- Pull the camera back, resume the match, and apply damage and knockback.
Hitstop itself is also a key source of game feel—freezing 2–4 frames on every normal hit, combined with screen shake, impact sparks, and sound effects, dramatically improves the sense of impact.
7. Round Structure and Result Flow
A best-of-three match is driven by a top-level match manager whose state flow is: character select → round start countdown → battle → round end (winner judged, round marker lit) → mid-match reset (positions and health restored, partial energy may carry over) → final result screen. Pause must freeze both the logic clock and the animation clock while blocking input. The core of local two-player mode is dual keyboard-zone mapping in the input layer, routing two key bindings to each character’s input buffer.
8. Common Quality Gaps and Optimization Paths
The prototype-stage “pretty homepage, janky combat” problem can be systematically addressed from these angles:
- Game feel: prioritize polishing hitstop, knockback displacement curves, and animation cancel windows before stacking more visual effects;
- Hit detection accuracy: use capsules or segmented bounding boxes for attack and hurtbox detection instead of intersecting raw model meshes;
- Performance: fixed logic frame rate (e.g., 60 steps/second) with render interpolation; quality-tier switches for particles and reflections; on-demand animation data loading;
- Balance: maintain a move data table and review startup frames, damage, and frame advantage (frame data after block) holistically, ensuring no move is absolutely unbeatable;
- Maintainability: make characters, moves, and AI parameters fully data-driven, so adding new characters requires no changes to core code.
9. Conclusion
A playable 3D fighting game is fundamentally a coordinated engineering effort across five systems: state machines, frame data, input buffering, AI decision-making, and camera language. AI-assisted coding tools can quickly scaffold the skeleton and visual prototype, but what truly determines match quality is the continuous refinement of game feel, hit detection rigor, and numerical balance. Hopefully, the general design approach broken down in this article will help developers building similar real-time competitive applications avoid detours and focus their effort where it most affects the player experience.
