Ai Combat System
AI Combat System
Section titled “AI Combat System”Enemy Character Classes
Section titled “Enemy Character Classes”AI Character Organization
Section titled “AI Character Organization”Create specialized enemy types by organizing AI characters into weapon-specific child classes:
Master AI Blueprint
Section titled “Master AI Blueprint”- Base Class: bp_character_coursera_ai_master
- Shared Systems: Combat state, health, movement, detection
- Override Functions: Attack behavior, weapon configuration
Enemy Variants
Section titled “Enemy Variants”Create child blueprints for each weapon type:
- bp_ai_shield: Sword and shield combat AI
- bp_ai_rifle: Ranged firearm combat AI
- bp_ai_bow: Archer combat AI
- bp_ai_mage: Magic-based combat AI
- bp_ai_dagger: Stealth/fast attack AI
- bp_ai_two_handed: Heavy weapon combat AI
Animation Stance Setup
Section titled “Animation Stance Setup”Configure each enemy type with appropriate weapon stance:
// AI Animation Stance ConfigurationF_AI_Set_Animation_Stance() {mesh.GetAnimInstance().Interface_Animation_Stance(Animation_Stance);}
// Child class defaults:// Shield AI: Animation_Stance = Shield// Rifle AI: Animation_Stance = Rifle// Bow AI: Animation_Stance = Bow// etc.
Attack Implementation
Section titled “Attack Implementation”AI Attack Framework
Section titled “AI Attack Framework”Create attack system that adapts to different weapon types:
Master Attack Function
Section titled “Master Attack Function”- F_AI_Attack: Empty function in master class for child overrides
- Target System: AI maintains reference to current attack target
- Rotation: AI faces target before attacking
Target Management
Section titled “Target Management”// AI Target ManagementOnPlayerAggro(Player) {Target = Player;LookAtTarget();}
OnResetCharacter() {Target = nullptr; // Clear target when resetting}
Attack Timing System
Section titled “Attack Timing System”Control when AI characters can attack:
Attack Range and Timing
Section titled “Attack Range and Timing”- Attack_Range Variable: Distance required to initiate attack (100-200 units for melee, 1000+ for ranged)
- Attack_Speed Variable: Cooldown between attacks (3 seconds default)
- Do Once Node: Prevent attack spam
Attack Validation
Section titled “Attack Validation”// AI Attack ValidationCE_Check_Attack_Range() {if (Target.IsValid() && !Dead && !Reset) {distance_to_target = Distance(GetActorLocation(), Target.GetActorLocation());
if (distance_to_target <= Attack_Range) {if (!Target.Interface_Get_Dead_State()) {F_AI_Attack(); // Execute attackStartAttackCooldown(Attack_Speed);} else {CE_Reset_AI_Character(); // Target died, reset AI}} else {AI_Move_To(Target.Location, Target, true); // Move closer}}}
Weapon-Specific Combat
Section titled “Weapon-Specific Combat”Melee Combat Implementation
Section titled “Melee Combat Implementation”For sword, dagger, and two-handed enemies:
Hitbox Setup
Section titled “Hitbox Setup”- Weapon_Hitbox: Box collision for weapon damage
- Socket Attachment: Attach to appropriate weapon socket
- Collision Management: Enable during attack animations, disable otherwise
Attack Integration
Section titled “Attack Integration”Copy player attack code and adapt for AI:
- Animation Montages: Use same attack animations as player
- Damage Values: Set appropriate damage for enemy type
- Timing: Use montage notify system for precise hit timing
Ranged Combat Implementation
Section titled “Ranged Combat Implementation”For bow, rifle, and magic enemies:
Projectile Attacks
Section titled “Projectile Attacks”- Spawn Projectile: Use existing projectile system
- Socket Locations: Weapon-appropriate spawn points (muzzle, arrow socket, hand)
- Range Advantage: Higher attack range (1000 units)
- Movement Distance: Stay at range (900-unit move-to radius)
// Ranged AI Attack Example// Magic AI AttackF_AI_Attack_Override() {PlayMontage(MagicAttack01);// Montage notify triggers projectile spawn}
Attack Rotation System
Section titled “Attack Rotation System”Multi-Attack AI
Section titled “Multi-Attack AI”Create more complex enemies with multiple attacks:
Random Attack Selection
Section titled “Random Attack Selection”- Random Integer: Generate random number for attack choice
- Switch Node: Route to different attack animations
- Attack Variety: 3-4 different attacks per boss-level enemy
Sequential Attack Rotation
Section titled “Sequential Attack Rotation”// Attack Rotation SystemF_AI_Attack_Boss() {Attack_Index++;if (Attack_Index > 3) {Attack_Index = 1; // Reset to first attack}
switch(Attack_Index) {case 1: PlayMontage(TwoHandedAttack01); break;case 2: PlayMontage(TwoHandedAttack02); break;case 3: PlayMontage(TwoHandedAttack03); break;}}
Combat Polish
Section titled “Combat Polish”Hit Registration
Section titled “Hit Registration”Ensure AI attacks properly register hits:
- Hitbox Override: Override F_Get_Melee_Hitbox function in each child class
- Collision Events: Implement overlap events for AI weapon hitboxes
- Player Targeting: Only damage player characters, not other AI
Movement Integration
Section titled “Movement Integration”- Attack Movement: Stop movement during attack animations
- Range Maintenance: Ranged AI maintain distance from player
- Positioning: Melee AI close distance for attack opportunities
Team System Integration
Section titled “Team System Integration”Team-Based Combat
Section titled “Team-Based Combat”Ensure AI respects team allegiance:
- Team Variable: Set AI team to “Enemy”
- Player Team: Set player team to “Player”
- Projectile Integration: AI projectiles only damage player team
- Friendly Fire Prevention: AI don’t damage each other
The AI combat system creates varied, challenging enemy encounters while maintaining clear, predictable behavior patterns that enhance gameplay rather than frustrate players.