Building a 3D Fighting Game Engine: FSM and Combat Logic Implementation

    Developing a 3D fighting game often presents a gap between high-quality character visuals and stiff combat mechanics. This article provides a technical guide to building the underlying combat architecture, covering Finite State Machine (FSM) design, frame data management, hit detection, AI behavior trees, camera systems, and network synchronization with cloud infrastructure support.

    Building a 3D Fighting Game Engine: FSM and Combat Logic Implementation

    In 3D action fighting game development, creators often face a common dilemma: characters look excellent during the modeling and display phases, but once they enter actual combat, the gameplay feels stiff, the logic becomes chaotic, and performance bottlenecks emerge. This gap between visual presentation and player experience fundamentally stems from an incomplete underlying combat system architecture. This article explores the core technology stack of 3D fighting games, providing a rigorous technical practice guide covering state machine design, combat hit detection, AI behavior control, system feedback, and resource management.

    1. Finite State Machine (FSM) and Combo System Design

    The soul of a fighting game lies in its “game feel,” which is fundamentally supported by a strict state machine and frame data management. A character cannot simultaneously be in a jumping and crouching state, and transitions between actions must follow strict priority and cancellation rules.

    1. State Division and Priority
    A complete fighting character typically includes the following basic states: Idle, Move, Dash, Jump, Block, Hit, Knockdown, and Skill/Super. State transitions require clearly defined conditions. For example, the Block state can only be entered from the Idle or Move states. During a Hit stun state, transitioning to any active attack state is impossible unless a specific mechanic (like a burst) is triggered.

    2. Frame Data and Cancel Chains
    The core logic of an action game is calculated in “frames.” Each attack action is divided into three phases:

    • Startup Frames: The preparation time before the action takes effect, during which the character is defenseless.
    • Active Frames: The period when the attack hitbox is active.
    • Recovery Frames: The ending lag after an attack misses or is blocked.

    The logic of combo cancellation dictates that if the current action is in the active frames or a specific phase of the recovery frames, and the player inputs a valid next command, the recovery frames of the current action are interrupted, directly transitioning into the startup frames of the next action. This mechanism requires marking animation events and verifying them within the logic layer.

    1. // Pseudo-code example: Action cancel logic validation
    2. public bool CanCancelCurrentAction(ActionState nextAction) {
    3. if (currentAction.IsActiveFrame() || currentAction.IsInCancelWindow()) {
    4. // Check if the next action is in the current action's allowed cancellation list
    5. return currentAction.cancelableActions.Contains(nextAction.id);
    6. }
    7. return false;
    8. }

    3. Air Juggles and Combos
    The juggle mechanic adds strategic depth to combat. When a character is hit by a specific strike and the impact force exceeds a threshold, their state transitions from Grounded Hit to Airborne Hit. At this point, gravity simulation and an air decay coefficient must be introduced to ensure the number of combo hits is limited by the system’s physics rules, preventing infinite combos from breaking game balance.

    2. Combat Hit Detection and Physical Interaction

    Hit detection in 3D space is much more complex than in 2D, involving capsule collisions, sweep tests, and spatial partitioning optimization.

    1. Hit Detection
    It is not recommended to rely entirely on the physics engine’s collision callbacks in a fighting game, as this leads to uncontrollable hit detection. The industry-standard approach is to use “shape sweep tests.” During active frames, a geometry shape (such as a sphere or capsule) is bound to the weapon or fist. Each frame, it sweeps in its direction of movement to detect intersection with the enemy character’s collision body.

    2. Throws and Instant Reversals
    Throws (command throws or normal throws) break conventional strike-and-block logic. Their detection is usually based on distance and facing direction. Once triggered, both parties enter a “locked state,” where the physics engine takes over their relative displacement and plays a preset paired animation. Throws possess “invincibility frames” or “super armor” attributes, but their startup frames are typically interrupted by regular strikes. This forms the classic “Throw beats Block, Strike beats Throw” mind game loop.

    3. Directional Input Supers and Input Buffering
    Fighting games feature extensive “motion inputs” (e.g., ↓ ↘ → + Attack). To ensure input recognition tolerance in a 3D environment, an input buffer queue must be established. The system records the player’s directional and button inputs at fixed time intervals (e.g., 100ms) and compares them against the skill table using a pattern matching algorithm. Once a match is successful and the character is in a state allowing the super to be released, the skill is triggered.

    3. AI Behavior Trees and Difficulty Scaling

    Designing single-player combat AI requires balancing challenge and fairness, avoiding a “perfect reaction AI” that frustrates players. A behavior tree-based architecture effectively manages the AI’s decision-making logic.

    1. Behavior Tree Node Design

    • Selector Node: Selects a macro strategy (offense, defense, zoning) based on the current situation (health difference, distance, energy value).
    • Sequence Node: Executes specific tactics, such as “Approach -> Check Distance -> Initiate Throw.”
    • Condition Node: Checks environmental states, such as “Is the player in stun?” or “Are they cornered?”

    2. Difficulty Scaling Parameter Control
    AI should not increase difficulty by changing game rules, but by adjusting decision parameters:

    • Reaction Delay: In easy mode, the delay between the AI receiving player input and reacting is set above 200ms; in hard mode, it can be shortened to 50ms.
    • Error Rate: Introduce random probabilities in block-and-punish situations. Easy AI has a higher chance of dropping their guard or whiffing attacks.
    • Combo Utilization: Easy AI only executes basic single hits; hard AI can execute complex air juggles and will guaranteed trigger a super move when at full energy.

    4. Presentation Layer: Super Move Cinematics and Camera System

    Visual impact is a key element of fighting game presentation, especially regarding the cinematic camera handling for super moves.

    1. Time Stop and VFX Playback
    When a super move is triggered, the system performs a global time dilation, setting the time scale to 0 or an extremely low value, masking all irrelevant logic calculations. Subsequently, the camera switches to a preset track, panning around the character.

    2. Screen Space Post-Processing
    To enhance the sense of impact, dynamic blur, color correction (such as high contrast, posterization), and screen distortion effects should be overlaid during the cinematic. Meanwhile, the UI layer hides unnecessary combat information, retaining only the super move name and its exclusive VFX mask.

    5. System Architecture: Multiplayer Sync and State Resolution

    Whether for local two-player split-screen or online matches, state synchronization is the top priority of the underlying architecture.

    1. Local Co-op and Split-Screen Rendering
    Local two-player modes typically utilize split-screen rendering. This requires strict decoupling between the logic and presentation layers. Inputs for both players are handled by their respective controllers, and the logic layer processes both sets of commands in a fixed order within the same Tick. The rendering layer must manage two independent camera view frustums and utilize frustum culling to save GPU overhead.

    2. Match Resolution and State Reset
    Adopting a best-of-three format requires robust state management between rounds. When one side’s health reaches zero, a RoundEnd event is triggered, freezing inputs and playing the victory/defeat animation. The system records the current round count; if the win condition is not met, it executes ResetRound: resetting both players’ health, energy meters, and position coordinates, while clearing residual projectiles and VFX entities from the scene.

    3. Cloud Assistance and Data Analysis
    In modern game architectures, cloud services play a crucial role. By integrating object storage and message queue services from general cloud providers, persistent storage for player match records and replay data can be achieved. Furthermore, utilizing cloud-based logging and monitoring alert systems allows developers to collect real-time data on player input latency, frame drops, and crash logs during combat. For online modes, container platforms deployed in the cloud can provide elastically scaling dedicated server instances, ensuring a low-latency multiplayer experience. Infrastructure providers like Baidu AI Cloud can also offer stable underlying computing power and network penetration support for such high-concurrency, low-latency real-time interactive scenarios.

    Conclusion

    Bridging the gap between detailed character modeling and fluid combat experience requires developers to invest significant engineering effort into underlying modules such as state machine logic, collision detection, AI decision trees, and camera control. Stripping away the visual flair and returning to precise control over “frames,” “states,” and “hit detection” is the only path to building a high-quality 3D fighting game. With rational architectural design and the support of cloud infrastructure, developers can focus more on polishing core gameplay, ultimately delivering a work that boasts both operational depth and visual tension.