With your player moving and looking around, the next step is weapons and combat. This lesson gets you to a working gun: fire input, hit detection (line trace), damage application, ammo, and basic hit feedback. You will finish with a weapon the player can aim and shoot, and targets that react to being hit.

Why weapon systems matter

Combat is the core loop of most FPS games. Getting it right early means:

  • You can test level flow and encounter design with real shooting.
  • You have a clear pattern for adding more weapons or abilities later.
  • You avoid reworking damage and hit logic when you add enemies and UI.

We will use line trace (hitscan) for simplicity: when the player fires, a ray is cast from the camera (or muzzle) and the first hit is processed. You can later swap to projectiles using the same damage and target logic.

Step 1: Weapon actor and first-person mesh

  1. Create a weapon Blueprint

    • In the Content Browser: Right-click, Blueprint Class, pick Actor. Name it something like BP_Weapon_Rifle.
    • Add a Skeletal Mesh or Static Mesh as the root (or under a "WeaponMesh" scene component). This is the gun the player sees in first person.
    • Attach it so it appears in front of the camera (e.g. under a "Weapon" socket or offset from the character's camera). Position and scale so it looks correct in first-person view.
  2. Attach the weapon to your character

    • Open your FPS character Blueprint. Add a Scene Component as a child of the camera (or the spring arm) — e.g. "WeaponSocket".
    • In the character's Begin Play or when the weapon is equipped, spawn BP_Weapon_Rifle and attach it to the WeaponSocket. Alternatively, place the weapon as a child in the Blueprint and set visibility/attachment in the editor.
    • Ensure the weapon moves and rotates with the camera so it feels like the player is holding it.

Pro tip: Keep weapon logic in the weapon Blueprint (firing, ammo, effects) and call into it from the character when the player presses fire. That keeps the character Blueprint from becoming huge and makes it easy to add more weapons later.

Step 2: Fire input and line trace

  1. Add fire input

    • In Project Settings > Input (or Enhanced Input): create an Input Action for "Fire" (e.g. Left Mouse Button or controller trigger).
    • In your character Blueprint, when Fire is triggered, call a function on the equipped weapon (e.g. "Try Fire") or run the trace from the character.
  2. Perform a line trace from the camera

    • Start: Use the camera's world location (e.g. GetCameraLocation() or the camera component's GetWorldLocation()).
    • End: Start + (camera forward vector × trace length). A typical length is 10000–20000 units so you can hit distant targets.
    • Use Line Trace by Channel (or Line Trace Single in Blueprint). Set the trace channel to something like "Visibility" or a custom "Weapon" channel so you can filter what can be hit.
    • Ignore the shooter: Add your character (or the owning pawn) to the "Actors to Ignore" array so you do not hit yourself.
  3. Process the hit result

    • If the trace returns a hit, you get Hit Actor, Hit Component, and Hit Location.
    • You will use these to apply damage, spawn impact effects, and (in a later lesson) drive enemy reactions.

Common mistake: Tracing from the wrong origin (e.g. character root instead of camera) makes the bullet feel misaligned with the crosshair. Always trace from the camera (or from a "muzzle" socket that is aligned with the camera view).

Step 3: Apply damage and health

  1. Give damageable actors a way to receive damage

    • On any actor that should take damage (e.g. a simple test cube or, later, an enemy), use the built-in Take Damage flow. In Blueprint: override or call Event Any Damage (or use the Apply Damage node and have the target handle it).
    • Alternatively, use a custom interface (e.g. "Damageable") with a "Apply Damage" function. When the line trace hits an actor that implements this interface, call Apply Damage with the hit location, damage amount, and instigator.
  2. Apply damage from the weapon

    • When the trace hits an actor: call Apply Damage (built-in) or your interface function. Pass a damage value (e.g. 10–25 for a rifle), the hit location, and the controller/pawn as instigator.
    • The damaged actor can then subtract from its health, play hit reactions, and destroy itself or switch to a "dead" state when health ≤ 0.
  3. Keep health on the target

    • On your test target (or enemy), store a variable like Current Health (e.g. 100). When damage is applied, subtract the value. When Current Health ≤ 0, run death logic (disable collision, play death animation, destroy or ragdoll, etc.).

Pro tip: Use Unreal's Damage Type (optional) to distinguish bullet damage from explosions or melee. You can subclass UDamageType and pass it to Apply Damage for different reactions per damage source.

Step 4: Ammo and fire rate

  1. Ammo variables

    • On the weapon: add Current Ammo (e.g. 30) and Max Ammo (e.g. 30). When the player fires, decrement Current Ammo by 1. If Current Ammo is 0, do not run the trace or fire logic — optionally play a "click" or "empty" sound.
  2. Fire rate

    • Prevent holding the mouse to spray infinitely: add a Last Fire Time (or a "Can Fire" flag). After firing, set a short cooldown (e.g. 0.1 seconds for semi-auto or 0.05 for automatic). Only allow the next fire when the cooldown has passed.
    • In Blueprint you can use Get Game Time In Seconds and compare to Last Fire Time + Fire Interval.
  3. Reload (optional for this lesson)

    • Add a "Reload" input. When pressed, set a "Is Reloading" flag, play a reload animation or timer (e.g. 2 seconds), then set Current Ammo back to Max Ammo and clear Is Reloading. While Is Reloading is true, block firing.

Step 5: Hit feedback – impacts and sound

  1. Impact effects at hit location

    • When the line trace hits something, get Hit Location and Hit Normal (and optionally Hit Component).
    • Spawn a particle system (e.g. bullet impact decal or spark effect) at Hit Location, using Hit Normal to orient the effect.
    • You can use different effects for different surface types (e.g. metal vs concrete) by checking the physical material or a custom tag on the hit component.
  2. Sound

    • Play a fire sound when the weapon shoots (attached to the weapon or the character).
    • Play an impact sound at the hit location (optional, based on surface type).
  3. Muzzle flash (optional)

    • Add a short-duration particle or light at the weapon muzzle (e.g. a socket on the mesh). Trigger it each time the weapon fires and let it auto-stop after a few frames.

These touches make the weapon feel responsive and readable even before you add enemies.

Step 6: Mini challenge – combat checklist

Before moving on, verify:

  • [ ] Pressing fire performs a line trace from the camera and hits geometry or test actors.
  • [ ] Hit actors receive damage and their health decreases; at 0 health they react (e.g. destroy or play death).
  • [ ] Ammo decreases per shot and firing is blocked when ammo is 0 (and optionally when reloading).
  • [ ] Fire rate is limited so the weapon cannot fire faster than intended.
  • [ ] Impact effect (and optionally sound) appears at the hit location.
  • [ ] Weapon mesh is visible in first person and aligned with the view.

If something feels off, double-check trace origin (camera), trace channel, and that the damaged actor is in the right collision channel so the trace can hit it.

Troubleshooting

Bullet does not hit where the crosshair is: Trace from the camera position and use the camera's forward vector. Do not use the character's forward vector unless the camera is locked to it with no pitch.

No damage applied: Ensure the hit actor has collision enabled and is on a channel the trace uses. Confirm you are calling Apply Damage (or your interface) with a valid damage value and that the target handles the event.

Weapon fires too fast or ignores ammo: Enforce fire interval with a time check and block fire when Current Ammo ≤ 0. Do not fire in Tick; fire only from the Fire input event.

Impact effect spawns in wrong place: Use the trace's Hit Location and Hit Normal from the line trace result; do not use the actor's root location.

What is next

With a working weapon and damage, you have the core of FPS combat. In Lesson 7: Enemy AI & Behavior Systems you will add enemies that take damage, react, and fight back so your levels have real threats.

For more on line traces and damage in Unreal, see the Unreal Engine 5 Documentation and our Unreal Engine Guide on the site.

Found this useful? Bookmark the course and try adding a second weapon or a simple reload animation. When you are ready, head to Lesson 7 to add enemy AI and behavior.