Melee Combat System
Melee Combat System
Section titled “Melee Combat System”Collision Detection Challenges
Section titled “Collision Detection Challenges”Before implementing melee combat, understand the collision detection problem: animations and projectiles moving at high speeds can “jump” large distances in a single frame, potentially missing targets. While advanced solutions exist, this implementation uses basic collision systems with awareness of potential limitations.
Basic Melee Setup
Section titled “Basic Melee Setup”Weapon Hitbox Creation
Section titled “Weapon Hitbox Creation”Add collision detection to character for melee attacks:
Right Hand Weapon Hitbox
Section titled “Right Hand Weapon Hitbox”- Component: Box Collision attached to right hand item socket
- Dimensions: Box extent 10x10x64 (sword-like dimensions)
- Position: Z location 60 to extend from hand
- Collision Settings: Custom collision, ignore all, overlap pawn only
- Default State: Collision disabled (enabled only during attacks)
Hit Detection Implementation
Section titled “Hit Detection Implementation”// Weapon Hitbox Overlap EventOnWeaponHitboxOverlap(OtherActor) {if (OtherActor != Self) {Interface_Health_Modify(OtherActor, Subtract, 25);}}
Kick Hitbox Setup
Section titled “Kick Hitbox Setup”Some attacks use kicks rather than weapon strikes:
Foot-Based Collision
Section titled “Foot-Based Collision”- Component: Box Collision attached to right toe base socket
- Dimensions: Box extent 16x16x32 for foot coverage
- Position: Z location -24 to align with foot
- Same Collision Settings: Custom collision, overlap pawn only
Timing Control System
Section titled “Timing Control System”Montage Notify Events
Section titled “Montage Notify Events”Control exactly when damage occurs during animations:
Montage Notify Setup
Section titled “Montage Notify Setup”- Timeline Positioning: Place timeline where attack should deal damage
- Add Notify: Right-click timeline > Add Notify > Montage Notify
- Notify Names: “melee_on” to enable damage, “melee_off” to disable damage
Notify Implementation
Section titled “Notify Implementation”// Montage Notify HandlerOnNotifyBegin(NotifyName) {if (NotifyName == 'melee_on') {set_damage_variable;enable_weapon_collision;} else if (NotifyName == 'melee_off') {disable_weapon_collision;clear_hit_actors_array;}}
Hit Prevention System
Section titled “Hit Prevention System”Ignore List Implementation
Section titled “Ignore List Implementation”Prevent multiple hits on same target during single attack:
Hit Actors Array
Section titled “Hit Actors Array”- Variable: Hit_Actors array to track damaged targets
- Add Unique: Only add each actor once per attack
- Pre-Check: Verify actor not already in array before dealing damage
// Hit Prevention LogicOnWeaponHitboxOverlap(OtherActor) {if (OtherActor != Self) {if (!Hit_Actors.Contains(OtherActor)) {Interface_Health_Modify(OtherActor, Subtract, Damage_Variable);Hit_Actors.AddUnique(OtherActor);}}}
Array Management
Section titled “Array Management”- Clear Array: Reset hit actors array when collision disables
- Attack Reset: Clear array for each new attack cycle
Damage System Integration
Section titled “Damage System Integration”Variable Damage System
Section titled “Variable Damage System”Allow different attacks to deal different damage:
- Damage Variable: Float variable set before each attack
- Flexible Values: Different attacks can set different damage amounts
- Interface Integration: Use existing health modification system
Melee Functions
Section titled “Melee Functions”Consolidated Melee Function
Section titled “Consolidated Melee Function”Create reusable function for all melee attacks:
F_Melee_Damage Function
Section titled “F_Melee_Damage Function”- Input: Other Actor (target of attack)
- Self Check: Verify not attacking own character
- Damage Application: Use damage variable for flexible damage amounts
- Hit Tracking: Manage hit actors array
F_Melee_Collision Function
Section titled “F_Melee_Collision Function”- Input: Notify Name, Weapon Boolean, Damage Amount
- Collision Management: Enable/disable appropriate hitbox
- Timing Control: Respond to montage notify events
- Hitbox Selection: Choose weapon hitbox or kick hitbox based on weapon boolean
Multiple Hitbox Support
Section titled “Multiple Hitbox Support”Support different attack types:
- Weapon Attacks: Use weapon hitbox attached to hand
- Kick Attacks: Use kick hitbox attached to foot
- Function Parameter: Boolean to select appropriate hitbox
Polish and Integration
Section titled “Polish and Integration”Animation Integration
Section titled “Animation Integration”Add melee notify events to all attack animations:
- Precise Timing: Place notify events at exact moment of impact
- Multiple Hits: Some animations may have multiple melee_on/melee_off pairs
- Copy/Paste: Use copy/paste to ensure consistent notify naming
Testing and Refinement
Section titled “Testing and Refinement”- Hit Registration: Verify all attacks register hits properly
- Double Hit Prevention: Confirm no double-hits occur
- Range Testing: Ensure hitboxes feel appropriate for visual attacks
- Performance: Monitor for any performance issues with collision
The melee combat system provides responsive, timing-based combat with proper hit detection and prevention of exploitation while maintaining visual consistency with attack animations.