Bevy All-in-One Documentation

A powerful 3D/2.5D game controller plugin for Bevy Engine.


Project maintained by yaskhan Hosted on GitHub Pages — Theme by mattgraham

Combat System - Comprehensive Documentation

Overview

The Combat System is a sophisticated, modular framework designed to handle all aspects of combat interactions in Bevy-based games. Built with flexibility and extensibility in mind, it supports a wide range of combat scenarios from simple melee encounters to complex tactical engagements. The system integrates seamlessly with other game systems such as AI, inventory, abilities, and UI to provide a cohesive combat experience.

Key Features:

Module Location: src/combat.rs


Table of Contents


Core Concepts

Combat Architecture

The Combat System is built on a modular, event-driven architecture that separates concerns and allows for easy extension. The system consists of several key layers:

  1. Core Layer: Contains fundamental combat components and systems
  2. Mechanics Layer: Implements specific combat mechanics (melee, ranged, blocking)
  3. Effects Layer: Handles combat effects (DoT, AoE, explosions)
  4. Integration Layer: Provides interfaces to other game systems
  5. Feedback Layer: Manages combat feedback (UI, sound, animations)

Damage Processing Pipeline

The damage processing pipeline is the heart of the combat system. It consists of the following stages:

  1. Event Generation: Combat actions generate damage events
  2. Target Resolution: Determines the target entity and damage receiver
  3. Damage Calculation: Applies multipliers, resistances, and modifiers
  4. Defense Processing: Checks for blocking, parrying, and other defensive actions
  5. Shield Application: Deducts damage from shields if available
  6. Health Application: Applies remaining damage to health
  7. Feedback Generation: Creates visual and audio feedback
  8. State Update: Updates combat states and triggers follow-up actions

Combat State Management

The combat system maintains state for all combat entities through a combination of components and resources:


Component Reference

Health

The Health component manages the life points and regeneration properties of combat entities.

Key Fields:

Behavior:

Shield

The Shield component provides a secondary health pool that absorbs damage before health.

Key Fields:

Behavior:

DamageReceiver

The DamageReceiver component is used for hitboxes or body parts that forward damage to a main Health component.

Key Fields:

Behavior:

MeleeCombat

The MeleeCombat component handles close-quarters attack capabilities.

Key Fields:

Behavior:

Blocking

The Blocking component provides defensive capabilities to reduce incoming damage.

Key Fields:

Behavior:

Parrying

The Parrying component extends blocking with perfect timing mechanics.

Key Fields:

Behavior:

DamageOverTime

The DamageOverTime component applies damage at regular intervals.

Key Fields:

Behavior:

AreaEffect

The AreaEffect component creates zones that apply effects to entities within range.

Key Fields:

Behavior:

Destroyable

The Destroyable component marks entities that can be destroyed.

Key Fields:

Behavior:

ExplosionSettings

The ExplosionSettings component configures explosion effects.

Key Fields:

Behavior:

CombatStats

The CombatStats component tracks combat-related statistics.

Key Fields:

Behavior:

CombatFeedback

The CombatFeedback component manages visual and audio feedback.

Key Fields:

Behavior:


System Integration

AI System Integration

The Combat System integrates with the AI System to provide intelligent combat behavior:

Integration Points:

Inventory System Integration

The Combat System works with the Inventory System to support weapon-based combat:

Integration Points:

Abilities System Integration

The Combat System integrates with the Abilities System to support special combat abilities:

Integration Points:

Stats System Integration

The Combat System works with the Stats System to provide character progression:

Integration Points:

UI System Integration

The Combat System integrates with the UI System to provide combat feedback:

Integration Points:

Physics System Integration

The Combat System works with the Physics System for realistic combat interactions:

Integration Points:


Combat Mechanics

Damage System

The damage system is the core of the combat mechanics, handling all aspects of damage calculation and application.

Damage Calculation:

Final Damage = Base Damage × General Multiplier × Part Multiplier × Resistance Factor × Random Factor

Damage Types:

Damage Processing:

  1. Calculate base damage
  2. Apply general damage multiplier
  3. Apply part-specific multiplier (if hit on damage receiver)
  4. Apply resistance based on damage type
  5. Apply random damage variation
  6. Check for blocking/parrying
  7. Apply shield absorption
  8. Apply remaining damage to health

Melee Combat

Melee combat handles close-quarters attacks with various detection methods.

Detection Methods:

Combo System:

Hit Reactions:

Ranged Combat

Ranged combat handles projectile-based attacks and ranged weapons.

Projectile Types:

Projectile Properties:

Ranged Mechanics:

Blocking and Parrying

Defensive mechanics to reduce or negate incoming damage.

Blocking:

Parrying:

Defensive States:

Combat Combos

The combo system allows for chaining attacks for increased damage and special effects.

Combo Properties:

Combo Execution:

  1. Player performs initial attack
  2. If next attack within combo window, increment combo level
  3. Apply combo damage multiplier
  4. Check for special attacks at current combo level
  5. Execute special attack if available
  6. Reset combo if no attack within combo window

Combo Feedback:

Critical Hits and Weak Spots

Critical hits provide bonus damage for precise attacks on weak spots.

Critical Hit Properties:

Weak Spot Properties:

Critical Hit Calculation:

  1. Check if attack hits weak spot
  2. If weak spot hit, apply weak spot multiplier
  3. Roll for critical hit based on critical chance
  4. If critical hit, apply critical multiplier
  5. Combine multipliers for final damage

Damage Over Time Effects

DoT effects apply damage at regular intervals over time.

DoT Types:

DoT Properties:

DoT Application:

  1. Apply initial DoT effect
  2. Start timer for next application
  3. Apply damage at each interval
  4. Check for stacking with existing effects
  5. Remove effect when duration expires

Area of Effect Attacks

AoE attacks affect multiple targets within a specified area.

AoE Types:

AoE Properties:

AoE Application:

  1. Determine area shape and size
  2. Find all entities within area
  3. Filter entities based on target filter
  4. Apply damage to each entity
  5. Apply damage falloff based on distance
  6. Repeat at specified intervals

Destructible Objects

Objects that can be destroyed through combat interactions.

Destructible Properties:

Destruction Process:

  1. Apply damage to destructible object
  2. Check if health falls below threshold
  3. Trigger destruction sequence
  4. Spawn debris if configured
  5. Trigger explosion if configured
  6. Play destruction sounds and effects
  7. Remove object from game

Explosions and Environmental Damage

Explosions provide area damage with physical force effects.

Explosion Properties:

Explosion Application:

  1. Determine explosion center and radius
  2. Find all entities within radius
  3. Calculate damage based on distance and falloff
  4. Apply physical force to entities
  5. Spawn visual explosion effect
  6. Play explosion sound
  7. Apply environmental damage (e.g., break windows, damage structures)

Advanced Features

Combat State Machine

The combat state machine manages the current state of combat entities.

Combat States:

State Transitions:

State Management:

Hit Detection Methods

Various methods for detecting combat hits.

Sphere Casting:

Ray Casting:

Hitbox Overlap:

Sweep Testing:

Damage Modifiers and Resistances

Systems for modifying damage based on various factors.

Damage Modifiers:

Resistances:

Resistance Calculation:

Effective Damage = Base Damage × (1.0 - Resistance Factor)

Combat Events and Callbacks

Event system for combat interactions.

Combat Events:

Event Callbacks:

Combat Animation Integration

Integration with animation system for combat visuals.

Animation Types:

Animation Triggers:

Combat Sound Effects

Audio feedback for combat actions.

Sound Types:

Sound Management:

Combat Camera Effects

Camera effects to enhance combat feel.

Camera Effects:

Effect Triggers:

Combat UI Feedback

User interface elements for combat feedback.

UI Elements:

UI Configuration:


Best Practices

Performance Optimization

Techniques for optimizing combat system performance.

Optimization Strategies:

Performance Tips:

Combat Balancing

Techniques for balancing combat mechanics.

Balancing Principles:

Balancing Techniques:

State Management

Best practices for managing combat state.

State Management Tips:

State Debugging:

Error Handling

Techniques for handling combat system errors.

Error Handling Strategies:

Common Error Types:

Testing Strategies

Approaches for testing combat systems.

Testing Levels:

Testing Techniques:


Troubleshooting

Common Issues

Frequently encountered combat system problems.

Hit Detection Issues:

Damage Calculation Issues:

State Management Issues:

Performance Issues:

Debugging Techniques

Methods for debugging combat systems.

Debugging Tools:

Debugging Strategies:

Performance Bottlenecks

Common performance issues in combat systems.

Performance Problems:

Optimization Approaches:


Advanced Implementation Patterns

Custom Damage Types

Creating and using custom damage types.

Custom Damage Type Creation:

  1. Define new damage type enum variant
  2. Implement damage calculation for new type
  3. Add resistance handling for new type
  4. Create visual effects for new type
  5. Add sound effects for new type

Custom Damage Type Usage:

Dynamic Combat Modifiers

Implementing modifiers that change during combat.

Dynamic Modifier Types:

Dynamic Modifier Implementation:

  1. Define modifier conditions
  2. Implement modifier application
  3. Handle modifier stacking
  4. Provide visual feedback
  5. Manage modifier duration

Combat AI Integration

Advanced AI integration for combat.

AI Combat Behaviors:

AI Combat Implementation:

  1. Define AI combat states
  2. Implement tactical decision making
  3. Handle group coordination
  4. Provide combat feedback to AI
  5. Balance AI difficulty levels

Multiplayer Combat Synchronization

Synchronizing combat across networked players.

Synchronization Challenges:

Synchronization Techniques:

Procedural Combat Generation

Generating combat scenarios procedurally.

Procedural Combat Elements:

Procedural Generation Techniques:


Future Enhancements

Proposed Extensions

Potential additions to the combat system.

Combat Enhancements:

System Integrations:

Roadmap

Planned development path for combat system.

Short-term Goals:

Medium-term Goals:

Long-term Goals:


Performance Characteristics

Computational Complexity

Analysis of combat system computational requirements.

Complexity Factors:

Complexity Analysis:

Memory Usage

Memory requirements for combat system.

Memory Components:

Memory Optimization:

Optimization Strategies

Techniques for optimizing combat system performance.

Optimization Approaches:


Real-World Usage Examples

Action RPG: Dynamic Combat System

Implementation of combat system in an action RPG.

Combat Features:

Implementation Details:

Tactical Shooter: Precision Combat

Combat system for a tactical shooter game.

Combat Features:

Implementation Details:

Survival Horror: Tension-Based Combat

Combat system for survival horror games.

Combat Features:

Implementation Details:

Fighting Game: Combo-Driven Combat

Combat system for fighting games.

Combat Features:

Implementation Details:


Integration Dependencies

Systems that the combat system depends on.

Core Dependencies:

Game System Dependencies:

Cross-System Communication

How combat system communicates with other systems.

Communication Methods:

Communication Patterns:


Appendix

Glossary

Key terms and definitions for the combat system.

Combat Terms:

Configuration Reference

Configuration options for the combat system.

Configuration Parameters:

Configuration Files:

Migration Guide

Guide for migrating from older combat system versions.

Migration Steps:

  1. Backup existing combat data
  2. Update to new combat system version
  3. Convert old combat components
  4. Update combat event handlers
  5. Test migrated combat scenarios
  6. Optimize migrated combat systems

Migration Tools:


Conclusion

The Combat System provides a comprehensive framework for implementing sophisticated combat mechanics in Bevy-based games. With its modular architecture, extensive feature set, and flexible integration capabilities, it can support a wide range of combat scenarios from simple melee encounters to complex tactical engagements.

This documentation covers all major aspects of the combat system, including core components, advanced features, integration points, best practices, and troubleshooting guidance. By following the patterns and recommendations outlined in this documentation, developers can create engaging and balanced combat experiences that integrate seamlessly with other game systems.

For the most up-to-date information and additional resources, please refer to the official repository and community forums. The combat system is continuously evolving, with new features and improvements being added regularly based on community feedback and development needs.