A powerful 3D/2.5D game controller plugin for Bevy Engine.
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
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:
The damage processing pipeline is the heart of the combat system. It consists of the following stages:
The combat system maintains state for all combat entities through a combination of components and resources:
The Health component manages the life points and regeneration properties of combat entities.
Key Fields:
current: f32 - Current health pointsmaximum: f32 - Maximum health pointscan_regenerate: bool - Whether health can regenerateregeneration_rate: f32 - Health points regenerated per secondregeneration_delay: f32 - Delay after damage before regeneration startsis_invulnerable: bool - Whether the entity is currently invulnerabletemporal_invincibility_duration: f32 - Duration of invincibility frames after damagelast_damage_time: f32 - Timestamp of last damage receivedlast_damage_source: Option<Entity> - Entity that last damaged this entityBehavior:
can_regenerate is trueregeneration_delay seconds of no damagetemporal_invincibility_duration secondsDeathEvent is triggeredThe Shield component provides a secondary health pool that absorbs damage before health.
Key Fields:
current: f32 - Current shield pointsmaximum: f32 - Maximum shield pointscan_regenerate: bool - Whether shield can regenerateregeneration_rate: f32 - Shield points regenerated per secondregeneration_delay: f32 - Delay after damage before regeneration startsis_active: bool - Whether the shield is currently activelast_damage_time: f32 - Timestamp of last damage receivedshield_type: ShieldType - Type of shield (Energy, Physical, Magical)Behavior:
The DamageReceiver component is used for hitboxes or body parts that forward damage to a main Health component.
Key Fields:
damage_multiplier: f32 - Scale incoming damage (e.g., 2.0 for headshots)is_weak_spot: bool - Flags hits as “Critical” for UI feedbackhealth_root: Entity - The entity with the Health component to damagehitbox_type: HitboxType - Type of hitbox (Head, Torso, Limb, etc.)armor_value: f32 - Additional armor value for this hitboxhit_reaction: HitReaction - Type of reaction to trigger on hitBehavior:
The MeleeCombat component handles close-quarters attack capabilities.
Key Fields:
damage: f32 - Base damage per attackrange: f32 - Maximum attack rangeattack_speed: f32 - Attacks per secondcombo_enabled: bool - Whether combos are enabledcombo_window: f32 - Time window to chain attackscombo_damage_multiplier: f32 - Damage multiplier for combo attackscurrent_combo_count: u32 - Current combo counterattack_animation: String - Animation to play during attackhit_animation: String - Animation to play on successful hitattack_sound: String - Sound to play during attackhit_sound: String - Sound to play on successful hitBehavior:
The Blocking component provides defensive capabilities to reduce incoming damage.
Key Fields:
block_reduction: f32 - Damage reduction factor (0.0-1.0)is_blocking: bool - Whether currently blockingblock_animation: String - Animation to play when blockingblock_sound: String - Sound to play when blockingblock_stamina_cost: f32 - Stamina cost per second of blockingcan_parry: bool - Whether parrying is enabledparry_window: f32 - Time window for successful parryparry_multiplier: f32 - Damage multiplier when parryingBehavior:
block_reduction factorThe Parrying component extends blocking with perfect timing mechanics.
Key Fields:
parry_window: f32 - Time window for successful parryparry_cooldown: f32 - Cooldown between parry attemptsparry_animation: String - Animation to play on successful parryparry_sound: String - Sound to play on successful parryparry_counter_attack: bool - Whether to enable counter attackscounter_attack_damage: f32 - Damage for counter attackslast_parry_time: f32 - Timestamp of last parry attemptBehavior:
The DamageOverTime component applies damage at regular intervals.
Key Fields:
damage_per_tick: f32 - Damage applied per intervaltick_frequency: f32 - Time between damage applicationstotal_duration: f32 - Total duration of the effectremaining_duration: f32 - Remaining time for the effectsource_entity: Option<Entity> - Entity that applied the DoTdamage_type: DamageType - Type of damage (Poison, Fire, Bleed, etc.)is_stackable: bool - Whether multiple instances can stackmax_stack_count: u32 - Maximum number of stacksBehavior:
The AreaEffect component creates zones that apply effects to entities within range.
Key Fields:
radius: f32 - Size of the effect zoneinterval: f32 - Time between effect applicationsdamage_type: DamageType - Type of effect (Damage, Heal, Buff, Debuff)effect_amount: f32 - Amount of effect per applicationduration: f32 - Total duration of the area effectis_pulsing: bool - Whether effect pulses or is continuoustarget_filter: TargetFilter - Filter for affected entitiesvisual_effect: String - Visual effect to displayBehavior:
The Destroyable component marks entities that can be destroyed.
Key Fields:
health_threshold: f32 - Health threshold for destructiondebris_prefab: Option<String> - Prefab to spawn on destructionexplosion_settings: Option<ExplosionSettings> - Explosion configurationdestruction_sound: String - Sound to play on destructiondestruction_effect: String - Visual effect on destructionis_destructible: bool - Whether currently destructibledestruction_delay: f32 - Delay before destruction after health threshold reachedBehavior:
The ExplosionSettings component configures explosion effects.
Key Fields:
radius: f32 - Explosion radiusdamage: f32 - Base damage at centerfalloff: f32 - Damage falloff with distanceforce: f32 - Physical force applieddamage_type: DamageType - Type of damageexplosion_prefab: String - Visual explosion prefabexplosion_sound: String - Explosion sound effectaffects_player: bool - Whether explosion affects playeraffects_enemies: bool - Whether explosion affects enemiesaffects_objects: bool - Whether explosion affects objectsBehavior:
The CombatStats component tracks combat-related statistics.
Key Fields:
total_damage_dealt: f32 - Total damage dealttotal_damage_received: f32 - Total damage receivedtotal_kills: u32 - Total killstotal_deaths: u32 - Total deathscritical_hits: u32 - Number of critical hitsblocks_successful: u32 - Successful blocksparries_successful: u32 - Successful parriescombo_max: u32 - Maximum combo achievedlongest_spree: u32 - Longest kill spreeBehavior:
The CombatFeedback component manages visual and audio feedback.
Key Fields:
damage_numbers_enabled: bool - Whether to show damage numbersdamage_number_style: DamageNumberStyle - Style configurationhit_effects_enabled: bool - Whether to show hit effectsblock_effects_enabled: bool - Whether to show block effectscritical_hit_effect: String - Effect for critical hitsweak_spot_effect: String - Effect for weak spot hitsdamage_sound: String - Sound for damageblock_sound: String - Sound for blockingparry_sound: String - Sound for parryingBehavior:
The Combat System integrates with the AI System to provide intelligent combat behavior:
Integration Points:
CombatAIPlugin - Main integration pluginAICombatBehavior - Component for AI combat configurationAICombatState - Tracks current AI combat stateAICombatEvents - Events for AI combat actionsThe Combat System works with the Inventory System to support weapon-based combat:
Integration Points:
WeaponCombatPlugin - Weapon combat integrationWeaponDamageCalculator - Calculates weapon-based damageAmmunitionTracker - Tracks ammunition usageWeaponDurability - Handles weapon durabilityThe Combat System integrates with the Abilities System to support special combat abilities:
Integration Points:
CombatAbilitiesPlugin - Combat abilities integrationAbilityDamageCalculator - Calculates ability-based damageAbilityCombatEffects - Handles ability combat effectsCombatAbilityCooldowns - Manages ability cooldownsThe Combat System works with the Stats System to provide character progression:
Integration Points:
CombatStatsPlugin - Combat stats integrationStatDamageCalculator - Calculates stat-based damageCombatStatModifiers - Handles stat-based modifiersCombatLevelScaling - Manages level-based scalingThe Combat System integrates with the UI System to provide combat feedback:
Integration Points:
CombatUIPlugin - Combat UI integrationHealthBarSystem - Manages health bar displayDamageNumberSystem - Handles damage number displayCombatNotificationSystem - Manages combat notificationsThe Combat System works with the Physics System for realistic combat interactions:
Integration Points:
CombatPhysicsPlugin - Combat physics integrationPhysicsHitDetection - Physics-based hit detectionCombatForceApplication - Handles force applicationCombatRagdollSystem - Manages ragdoll physicsThe 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:
Physical - Standard physical damageSlashing - Slashing weapon damagePiercing - Piercing weapon damageBlunt - Blunt weapon damageFire - Fire-based damageIce - Ice-based damageLightning - Lightning-based damagePoison - Poison-based damageHoly - Holy/magical damageDark - Dark/necrotic damageDamage Processing:
Melee combat handles close-quarters attacks with various detection methods.
Detection Methods:
Combo System:
Hit Reactions:
Ranged combat handles projectile-based attacks and ranged weapons.
Projectile Types:
Projectile Properties:
speed: f32 - Projectile speedrange: f32 - Maximum rangedamage: f32 - Base damagepiercing: bool - Whether projectile pierces targetshoming: bool - Whether projectile homes on targetsexplosion: Option<ExplosionSettings> - Explosion on impactRanged Mechanics:
Defensive mechanics to reduce or negate incoming damage.
Blocking:
Parrying:
Defensive States:
The combo system allows for chaining attacks for increased damage and special effects.
Combo Properties:
combo_window: f32 - Time window to chain attackscombo_damage_multiplier: f32 - Damage multiplier per combo levelmax_combo_level: u32 - Maximum combo levelcombo_reset_time: f32 - Time before combo resetscombo_special_attacks: Vec<ComboSpecialAttack> - Special attacks at combo levelsCombo Execution:
Combo Feedback:
Critical hits provide bonus damage for precise attacks on weak spots.
Critical Hit Properties:
critical_chance: f32 - Chance for critical hit (0.0-1.0)critical_multiplier: f32 - Damage multiplier for critical hitscritical_effect: String - Visual effect for critical hitscritical_sound: String - Sound for critical hitsWeak Spot Properties:
weak_spot_multiplier: f32 - Damage multiplier for weak spotsweak_spot_effect: String - Visual effect for weak spot hitsweak_spot_sound: String - Sound for weak spot hitsweak_spot_hitbox: Entity - Hitbox entity for weak spotCritical Hit Calculation:
DoT effects apply damage at regular intervals over time.
DoT Types:
Poison - Nature-based damage over timeBleed - Physical damage over timeBurn - Fire-based damage over timeCorrosion - Acid-based damage over timeRadiation - Radiation-based damage over timeHolyBurn - Holy damage over timeDarkCorruption - Dark damage over timeDoT Properties:
damage_per_tick: f32 - Damage per applicationtick_frequency: f32 - Time between applicationstotal_duration: f32 - Total durationis_stackable: bool - Whether effects can stackmax_stack_count: u32 - Maximum stacksstack_damage_multiplier: f32 - Damage multiplier per stackDoT Application:
AoE attacks affect multiple targets within a specified area.
AoE Types:
Circular - Circular area around pointCone - Cone-shaped area in directionLine - Line-shaped areaRectangular - Rectangular areaCustom - Custom-shaped areaAoE Properties:
radius: f32 - Size of areashape: AoEShape - Shape of areadamage: f32 - Base damagefalloff: f32 - Damage falloff with distancetarget_filter: TargetFilter - Filter for affected entitiesapplication_interval: f32 - Time between applicationsAoE Application:
Objects that can be destroyed through combat interactions.
Destructible Properties:
health_threshold: f32 - Health threshold for destructiondebris_prefab: Option<String> - Prefab to spawn on destructionexplosion_settings: Option<ExplosionSettings> - Explosion configurationdestruction_sound: String - Sound to play on destructiondestruction_effect: String - Visual effect on destructionis_destructible: bool - Whether currently destructibleDestruction Process:
Explosions provide area damage with physical force effects.
Explosion Properties:
radius: f32 - Explosion radiusdamage: f32 - Base damage at centerfalloff: f32 - Damage falloff with distanceforce: f32 - Physical force applieddamage_type: DamageType - Type of damageexplosion_prefab: String - Visual explosion prefabexplosion_sound: String - Explosion sound effectExplosion Application:
The combat state machine manages the current state of combat entities.
Combat States:
Idle - Not in combatEngaged - In combatAttacking - Currently attackingBlocking - Currently blockingDodging - Currently dodgingStunned - Stunned and unable to actDead - DeadState Transitions:
State Management:
Various methods for detecting combat hits.
Sphere Casting:
Ray Casting:
Hitbox Overlap:
Sweep Testing:
Systems for modifying damage based on various factors.
Damage Modifiers:
General Multiplier - Global damage multiplierPart Multiplier - Multiplier for specific body partsCritical Multiplier - Multiplier for critical hitsCombo Multiplier - Multiplier for combo attacksElemental Multiplier - Multiplier for elemental damageResistances:
Physical Resistance - Resistance to physical damageElemental Resistance - Resistance to elemental damageMagic Resistance - Resistance to magical damageSpecific Resistance - Resistance to specific damage typesResistance Calculation:
Effective Damage = Base Damage × (1.0 - Resistance Factor)
Event system for combat interactions.
Combat Events:
DamageEvent - Triggered when damage is appliedBlockEvent - Triggered when damage is blockedParryEvent - Triggered when damage is parriedCriticalHitEvent - Triggered on critical hitsDeathEvent - Triggered when entity diesComboEvent - Triggered on combo executionDoTAppliedEvent - Triggered when DoT is appliedAoEAppliedEvent - Triggered when AoE is appliedEvent Callbacks:
Integration with animation system for combat visuals.
Animation Types:
Attack Animations - Different animations for attack typesBlock Animations - Animations for blockingParry Animations - Animations for parryingHit Reactions - Animations for being hitDeath Animations - Animations for dyingSpecial Attacks - Unique animations for special attacksAnimation Triggers:
Audio feedback for combat actions.
Sound Types:
Attack Sounds - Sounds for different attack typesHit Sounds - Sounds for successful hitsBlock Sounds - Sounds for blockingParry Sounds - Sounds for parryingCritical Hit Sounds - Sounds for critical hitsDeath Sounds - Sounds for dyingEnvironmental Sounds - Sounds for environmental interactionsSound Management:
Camera effects to enhance combat feel.
Camera Effects:
Screen Shake - Shakes screen on heavy hitsSlow Motion - Slows time for dramatic momentsZoom In - Zooms in on critical hitsField of View - Adjusts FOV for combat intensityCamera Angle - Changes angle for special attacksMotion Blur - Adds blur for fast movementsEffect Triggers:
User interface elements for combat feedback.
UI Elements:
Health Bars - Shows health and shield statusDamage Numbers - Floating damage numbersCombo Meter - Shows current combo levelStamina Bar - Shows stamina for blocking/dodgingCooldown Timers - Shows ability cooldownsHit Indicators - Shows hit direction and typeKill Feed - Shows recent kills and combat eventsUI Configuration:
Techniques for optimizing combat system performance.
Optimization Strategies:
Performance Tips:
Techniques for balancing combat mechanics.
Balancing Principles:
Balancing Techniques:
Best practices for managing combat state.
State Management Tips:
State Debugging:
Techniques for handling combat system errors.
Error Handling Strategies:
Common Error Types:
Approaches for testing combat systems.
Testing Levels:
Testing Techniques:
Frequently encountered combat system problems.
Hit Detection Issues:
Damage Calculation Issues:
State Management Issues:
Performance Issues:
Methods for debugging combat systems.
Debugging Tools:
Debugging Strategies:
Common performance issues in combat systems.
Performance Problems:
Optimization Approaches:
Creating and using custom damage types.
Custom Damage Type Creation:
Custom Damage Type Usage:
Implementing modifiers that change during combat.
Dynamic Modifier Types:
Dynamic Modifier Implementation:
Advanced AI integration for combat.
AI Combat Behaviors:
AI Combat Implementation:
Synchronizing combat across networked players.
Synchronization Challenges:
Synchronization Techniques:
Generating combat scenarios procedurally.
Procedural Combat Elements:
Procedural Generation Techniques:
Potential additions to the combat system.
Combat Enhancements:
System Integrations:
Planned development path for combat system.
Short-term Goals:
Medium-term Goals:
Long-term Goals:
Analysis of combat system computational requirements.
Complexity Factors:
Complexity Analysis:
Memory requirements for combat system.
Memory Components:
Memory Optimization:
Techniques for optimizing combat system performance.
Optimization Approaches:
Implementation of combat system in an action RPG.
Combat Features:
Implementation Details:
Combat system for a tactical shooter game.
Combat Features:
Implementation Details:
Combat system for survival horror games.
Combat Features:
Implementation Details:
Combat system for fighting games.
Combat Features:
Implementation Details:
Systems that the combat system depends on.
Core Dependencies:
Game System Dependencies:
How combat system communicates with other systems.
Communication Methods:
Communication Patterns:
Key terms and definitions for the combat system.
Combat Terms:
Configuration options for the combat system.
Configuration Parameters:
Configuration Files:
combat_config.ron - Main configuration filedamage_types.ron - Damage type definitionshit_detection.ron - Hit detection configurationfeedback.ron - Feedback configurationperformance.ron - Performance tuningGuide for migrating from older combat system versions.
Migration Steps:
Migration Tools:
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.