Unreal 4 C++ – Toon Tanks Game


Toon Tanks is a third-person top-down tank shooter prototype built in Unreal 4 with C++ and Blueprints, my third Unreal project and the first one with a real-time gameplay loop involving movement, aiming, projectiles, and health. The player controls a tank using WASD while independently rotating the turret to follow the mouse cursor, and the goal is to destroy all enemy turrets before they deplete the tank’s health. Each turret detects when the player enters or exits its range and responds by opening or stopping fire accordingly. The project introduced the core pillars of arcade-style game feel in Unreal: pawn setup, input handling, projectile physics, damage, and a simple but complete game state flow.


🎮 Pawn & Input Setup

  • The player tank is a custom APawn subclass with separate components for the tank body and the turret mesh, allowing independent rotation between the two — the body follows movement direction, the turret tracks the mouse.
  • Movement uses AddActorLocalOffset driven by WASD input, keeping the tank grounded without a full UCharacterMovementComponent — appropriate for a top-down vehicle that doesn’t need jumping or gravity handling.
  • Turret rotation is computed each tick by projecting a mouse-to-world ray via APlayerController::DeprojectMousePositionToWorld and rotating the turret mesh toward the resulting hit point on the ground plane, decoupling aim from movement entirely.

💥 Projectile System

  • Projectiles are AActor subclasses with a UProjectileMovementComponent handling physics-based flight — initial speed, gravity scale, and bounce behavior are all configurable via UPROPERTY(EditAnywhere) so they can be tuned from the Details panel without recompiling.
  • On hit, the projectile queries the struck actor for a damage interface and applies a fixed damage value before destroying itself, keeping the projectile decoupled from any specific target type.
  • Both the player tank and enemy turrets spawn projectiles from the same base class — the shooter just passes itself as the instigator, which is used downstream by the damage system to prevent self-damage.

❤️ Health & Damage

  • Both the player tank and enemy turrets share a health system implemented directly on each pawn, tracking current health against a max value exposed as UPROPERTY(EditAnywhere).
  • Damage is applied via Unreal’s built-in UGameplayStatics::ApplyDamage and received through the OnTakeAnyDamage delegate, which keeps the damage pipeline consistent across all damageable actors without custom interfaces.
  • When health reaches zero, the actor triggers a death sequence — particle effect, sound, and then Destroy() — and notifies the game mode to check win/loss conditions.

🏰 Enemy Turret AI

  • Enemy turrets are stationary AActor subclasses that use a UBoxComponent overlap to detect when the player tank enters or exits their fire range — no AI controller or behavior tree needed for this level of behavior.
  • On overlap begin, a looping timer via FTimerManager::SetTimer triggers the fire function at a fixed interval; on overlap end, ClearTimer stops it. This pattern is simpler and cheaper than ticking every frame to check distance.
  • The turret rotates each tick toward the player’s location using FMath::RInterpTo for smooth interpolated tracking, giving it a mechanical feel without snapping instantly to the target.

🏁 Game State & Flow

  • A custom AGameModeBase subclass tracks the number of living turrets and the player’s alive state, checking after each death whether the win or loss condition has been met.
  • On game end, the mode calls a Blueprint-implementable event to trigger the end screen — keeping the C++ side responsible for logic and the Blueprint side responsible for UI and presentation, a clean separation that avoids coupling game rules to widget code.
  • A start delay is handled via a one-shot timer that re-enables player input after a countdown, giving the player a moment to orient before turrets begin firing.

Demo: https://www.youtube.com/watch?v=lz8ko6A3rH8
Teaching Playlist: YouTube Playlist
Learning Source: Unreal Engine – The Ultimate Shooter Course (Udemy)

Leave a comment

Create a website or blog at WordPress.com

Up ↑