Skip to main content

Combat

The drone can detect an enemy, close in, aim, and open fire — dealing damage you wire into your own health system. Combat is optional: it lives in a single reusable component (BP_DroneWeaponComponent), and a drone without it simply flies and patrols exactly as before.

How an engagement plays out

  1. Detect. The drone spots a hostile target — the same friend/foe rule as the rest of the AI (a Character that doesn't carry the FriendlyTag). See How It Works → Who the drone targets.
  2. Alert. It holds for a brief DetectionDelay — a moment to react before it commits — then begins the chase.
  3. Close + aim. As it crosses FiringRange the body pitches and yaws to point its guns at the target.
  4. Fire. Once the muzzle is within FireAimTolerance it opens fire — while still closing in — and keeps firing from its hover spot.

The engagement breaks (and firing stops) on any of three things, which are the player's three counters:

  • Outrun it — leave FiringRange.
  • Break line of sight — duck behind cover.
  • Out-juke the turn — strafe faster than the drone can swing its guns (TurnSpeed).

Aiming — fixed guns that converge

The guns are bolted to the body, so the drone rotates the whole body to aim (pitch clamped by MaxAimPitch so it never points comically straight up or down). On a multi-barrel model the side barrels converge on the target — they meet where the body is pointing, so a well-aimed drone lands both beams on the target and a mis-aimed one sends them wide. This keeps "am I aimed?" honest: the aim gate and the actual beams use the same body-forward direction.

What the shots hit

Shots are an object trace against WeaponObjectTypes (by default WorldStatic, WorldDynamic, and Pawn):

  • Enemies are hit automatically. Characters and Pawns are the Pawn object type, so they register hits with no per-target collision setup.
  • Walls block shots. WorldStatic / WorldDynamic geometry stops a beam, so cover works.
Why object types, not the Visibility channel

A line trace on the Visibility channel passes straight through Characters — the standard Pawn collision profile ignores Visibility (so the camera doesn't collide with players). Tracing by object type sidesteps that, so your enemies are shootable out of the box. To make something un-shootable, keep it off those object types (or remove the type from WeaponObjectTypes). See Collision Setup.

Dealing damage — hook into your own health system

Each shot that lands carries a Damage value (how hard this drone hits). When a shot connects with the target, the drone does two things on the server:

  1. Calls Unreal's standard Apply Point Damage on the target.
  2. Broadcasts its own OnHitTarget event.

You can receive the hit either way — pick whichever fits your project:

A. Engine damage events (most reusable). On your target actor, implement Event AnyDamage (or Event OnTakePointDamage if you want the hit location/direction) and subtract from your own health. This works with any actor and couples to nothing in this pack:

Your enemy actor:
Event AnyDamage (Damage) ──► Health = Health − Damage ──► (Health <= 0?) Die

B. The OnHitTarget dispatcher. Bind it on the drone's DroneWeapon component for fully custom handling — score, hit markers, your own damage routine:

OnHitTarget (HitActor, DamageAmount, Hit, HitDirection) ──► your handler

Use DamageTypeClass to tag the damage (e.g. an Explosive/Energy DamageType) so your health system can react differently per type. Damage is applied once per shot, regardless of how many barrels land — so Damage reads as a clean per-shot number.

No health system is imposed

This pack deals damage; your game owns health. A target with no damage handling simply takes fire harmlessly — nothing breaks.

Multiplayer

Combat is built server-authoritative, which is exactly where health belongs in multiplayer:

  • Firing, hit traces, and damage all run on the server. Apply Point Damage fires your target's damage event on the server — reduce a replicated health value there and it shows on every client, the standard Unreal pattern.
  • The drone's aim replicates. The aiming pitch and yaw are replicated, so remote clients see the drone tilt and face its target while engaging — not just the host.

Setup checklist

  1. Put a BP_DroneWeaponComponent on your drone. (The included BP_AIDrone already has one.)
  2. Set Damage, and confirm the gun's muzzle sockets exist on the mesh (named with MuzzleSocketPrefix).
  3. Assign your muzzle / impact / projectile FX and fire sound on the component.
  4. To take damage, give your enemy actor an Event AnyDamage (or bind OnHitTarget).

Combat tuning

PropertyDefaultWhat it does
Damage10Damage dealt per landed shot.
FiringRangeHow close the drone must be to open fire.
FireIntervalSeconds between shots (rate of fire).
FireAimToleranceHow tightly the body must be aimed before it fires (wider = harder for the target to juke out).
MaxAimPitch60Clamp (degrees) on how far the nose pitches up/down to aim.
DetectionDelayThe Alert pause between spotting a target and committing to the chase.
WeaponObjectTypesWorldStatic, WorldDynamic, PawnObject types a shot can hit (what's shootable, what blocks).

Full property lists are in the Blueprint Reference.