Unreal 4 C++ – Third Person Shooter


A third-person shooter built with Unreal Engine 4.27 and C++, following the Unreal Engine – The Ultimate Shooter Course as a structural foundation. The project covers a wide range of gameplay systems: a data-driven multi-weapon inventory, dynamic crosshair, aim zoom, pickup interpolation, melee enemy AI driven by Behavior Trees, and a final boss. Level geometry and character assets come from the Marketplace; all gameplay logic is implemented in C++.


The Weapon System is fully data-driven through a UDataTable. Each row stores all properties for a weapon type — mesh, sounds, crosshair textures, damage values, fire rate, magazine capacity, and Animation Blueprint reference. AWeapon::OnConstruction loads the matching row at construction time and applies every property automatically. Adding a new weapon requires only a new DataTable row and a new EWeaponType enum entry — no C++ changes.

  • Three weapon types implemented: submachine gun, assault rifle, and pistol. The pistol includes a slide displacement animation driven by a UCurveFloat.
  • Each weapon tracks its own ammo count and magazine capacity, with independent per-type carried ammo stored in a TMap<EAmmoType, int32> on the player character.
  • Weapons support both single-fire and automatic fire modes, gated through ECombatState to prevent action conflicts during reload, equip, or stun.
  • Reloading uses AnimNotify callbacks (GrabClip / ReleaseClip) to drive the left hand IK and clip bone visibility in sync with the montage.

The Item Pickup System animates every pickup through a smooth camera-space arc before snapping to the equipped slot. AItem is the abstract base class for all pickups, handling the interpolation curve, glow material, rarity, and proximity widget.

  • Seven USceneComponent anchors are attached to the follow camera on the player — one reserved for weapon swaps, six for ammo pickups. Items pick the anchor with the lowest active item count and interpolate toward it each Tick using FInterpTo.
  • Item rarity (EItemRarity) maps to a FItemRarityTable DataTable row that drives glow color, fresnel parameters, star count, and custom depth stencil value for outline rendering.
  • A looping UCurveVector pulses the emissive glow and fresnel on idle ground items. A separate UCurveVector drives the scale during the pickup interp arc.
  • AAmmo pickups use an additional USphereComponent for auto-collection: walking through it starts the interp curve without requiring the interact button. If the equipped weapon’s clip is empty and the ammo type matches, a reload triggers automatically.

The Crosshair System computes a CrosshairSpreadMultiplier each frame as the sum of four independently interpolated factors: movement speed (mapped range), in-air state, aiming zoom, and post-shot spread. Blueprint reads the multiplier to scale five crosshair textures (center, top, bottom, left, right) independently, giving each weapon its own visual crosshair shape loaded from the DataTable.


The Combat System on AShooterCharacter uses a two-pass line trace for firing. A first trace from the screen crosshair finds the visual aim point; a second trace from the barrel socket to that point (extended by 25%) resolves the actual hit. This corrects the parallax mismatch between crosshair and barrel in a third-person camera without requiring manual offset tuning per weapon.

  • Hit results are routed through IBulletHitInterface, decoupling the fire logic from specific actor types. Any world actor — enemy, explosive barrel, or Blueprint subclass — can react to being shot by implementing BulletHit_Implementation without the player character needing to cast.
  • Headshot detection compares the hit bone name against AEnemy::HeadBoneName. Headshots apply a separate damage value from the DataTable and display a distinct hit number widget.
  • Crouch toggles bCrouching, reduces MaxWalkSpeed and increases GroundFriction, and smoothly interpolates the capsule half-height each frame to avoid mesh pop during transitions.

The Enemy AI uses a two-sphere aggro model backed by Behavior Trees. AgroSphere overlap sets the Blackboard Target key to start pursuit; CombatSphere overlap sets InAttackRange to trigger melee attacks. Enemies patrol between two editor-placed waypoints stored as local-space vectors and converted to world space at BeginPlay.

  • Melee hit detection uses UBoxComponent weapons on the left and right weapon bones, activated only during the attack animation window via ActivateLeftWeapon / ActivateRightWeapon Blueprint-callable functions called from AnimNotifies.
  • On bullet hit, enemies roll against a configurable StunChance (0–1). A successful roll plays the hit-react montage, writes the Stunned Blackboard key, and interrupts the current attack sequence.
  • Floating damage numbers are spawned as UUserWidget instances, tracked in a TMap<UUserWidget*, FVector>, and repositioned each Tick via ProjectWorldToScreen. Each widget is destroyed after a configurable delay.
  • A final boss enemy shares the same C++ architecture with tuned parameters. Killing it triggers the win condition for the level.

The Animation System on UShooterAnimInstance handles turn-in-place, lean, recoil weight, and FABRIK. Turn-in-place accumulates a RootYawOffset while the character is stationary; when it exceeds 90°, the Turning animation curve drives a rotation delta that is subtracted from the offset each frame, rotating the root back under the upper body without snapping. The lean system computes the yaw delta between consecutive frame actor rotations and interpolates toward it with FInterpTo, clamped to ±90°. bShouldUseFABRIK disables left-hand IK during reload and equip montages to prevent the hand from fighting the clip-grab animation.


GitHub Repository

Demo

Learning Source

Leave a comment

Create a website or blog at WordPress.com

Up ↑