Skip to content
Pablo Rodriguez

Melee Combat System

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.

Add collision detection to character for melee attacks:

  • 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)
// Weapon Hitbox Overlap Event
OnWeaponHitboxOverlap(OtherActor) {
if (OtherActor != Self) {
Interface_Health_Modify(OtherActor, Subtract, 25);
}
}

Some attacks use kicks rather than weapon strikes:

  • 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

Control exactly when damage occurs during animations:

  1. Timeline Positioning: Place timeline where attack should deal damage
  2. Add Notify: Right-click timeline > Add Notify > Montage Notify
  3. Notify Names: “melee_on” to enable damage, “melee_off” to disable damage
// Montage Notify Handler
OnNotifyBegin(NotifyName) {
if (NotifyName == 'melee_on') {
set_damage_variable;
enable_weapon_collision;
} else if (NotifyName == 'melee_off') {
disable_weapon_collision;
clear_hit_actors_array;
}
}

Prevent multiple hits on same target during single attack:

  • 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 Logic
OnWeaponHitboxOverlap(OtherActor) {
if (OtherActor != Self) {
if (!Hit_Actors.Contains(OtherActor)) {
Interface_Health_Modify(OtherActor, Subtract, Damage_Variable);
Hit_Actors.AddUnique(OtherActor);
}
}
}
  • Clear Array: Reset hit actors array when collision disables
  • Attack Reset: Clear array for each new attack cycle

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

Create reusable function for all melee attacks:

  • 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
  • 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

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

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
  • 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.