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
APawnsubclass 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
AddActorLocalOffsetdriven by WASD input, keeping the tank grounded without a fullUCharacterMovementComponent— 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::DeprojectMousePositionToWorldand rotating the turret mesh toward the resulting hit point on the ground plane, decoupling aim from movement entirely.
💥 Projectile System
- Projectiles are
AActorsubclasses with aUProjectileMovementComponenthandling physics-based flight — initial speed, gravity scale, and bounce behavior are all configurable viaUPROPERTY(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::ApplyDamageand received through theOnTakeAnyDamagedelegate, 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
AActorsubclasses that use aUBoxComponentoverlap 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::SetTimertriggers the fire function at a fixed interval; on overlap end,ClearTimerstops 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::RInterpTofor smooth interpolated tracking, giving it a mechanical feel without snapping instantly to the target.
🏁 Game State & Flow
- A custom
AGameModeBasesubclass 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