Skip to main content

Customization

Teams, tuning, damage, multiplayer and your own turret model. The names of all properties and functions are in the Blueprint Reference.

Teams​

The plugin uses Unreal's IGenericTeamAgentInterface, the team interface of the engine's AI. Every turret has a TeamID; the controller copies it from the turret it possesses. A team ID of 255 means no team.

GetTeamAttitude on the controller decides how the turret treats an actor:

Other actorAttitude
Pawn of the same teamFriendly, ignored
Pawn of another teamHostile, attacked
Pawn without a teamHostile, attacked
Anything that is not a pawnNeutral, ignored

A pawn has a team when the pawn itself or its controller implements IGenericTeamAgentInterface.

Giving the player a team​

  • Set Examples/Blueprints/B_TeamPlayerController as your GameMode's Player Controller Class and set its TeamID, or
  • derive your own player controller from the C++ class ATeamPlayerController, or
  • implement IGenericTeamAgentInterface on your own pawn or controller in C++.

Changing teams at runtime​

The turret's AI perception keeps its view of an actor until it is updated. After changing a team, call Request Stimuli Listener Update on the AIPerception component of every ATurretAIController, as B_TeamPad does.

Your own friend/foe rule​

GetTeamAttitude is a Blueprint Native Event. Create a child of B_TurretAIController, override GetTeamAttitude and return the attitude you want; call the parent to keep the default rule for the other cases. B_TurretAIController_AlwaysFriendly returns Friendly for everyone. Set your controller as the turret's AI Controller Class.

Tuning​

Detection range and field of view​

Open the controller (for example a child of B_TurretAIController), select the AIPerception component and go to AI Perception → Senses Config → Index [0] → Sense:

  • Sight Radius: maximum detection distance
  • Lose Sight Radius: keep it a little higher than Sight Radius
  • Peripheral Vision Half Angle: 90° gives a 180° field of view

Fire rate and tracking​

On the controller:

PropertyDefaultMeaning
ShootProjectileTimerRate0.7Seconds between shots
TrackPlayerTimerRate0.1Seconds between aim updates
TrackingTimeout3.0Seconds without the target in sight before the turret resets
ShootingActive, TrackingActivetrueSwitch firing or tracking off

Projectile speed and barrels​

On the turret:

PropertyDefault in C++Meaning
Projectile Velocity (VelocityScale)1000Projectile speed in cm/s
bDualBarrelfalseFire from both barrels
DualBarrelShootDelay0.2Seconds before the second barrel fires
ProjectileClassATurretPlasmaProjectileProjectile to spawn; B_TurretPawn uses B_TurretProjectile

The lead calculation uses the projectile velocity, so faster or slower projectiles still hit. No correction factor is needed.

Damage​

The projectiles deal no damage by default. They destroy themselves on impact and call the turret's OnProjectileImpact event. To make them hurt:

  1. Open B_TurretPawn or a child of it.
  2. Implement the event OnProjectileImpact.
  3. Call Apply Damage with OtherActor as the damaged actor, or apply a Gameplay Effect as in the Lyra Integration.
Multiplayer

Every machine spawns its own projectiles, so OnProjectileImpact runs on every machine. Put a Has Authority check (Switch Has Authority) in front of the damage, or clients apply it too.

The turrets themselves have no health in this version. To make them destructible, add your own health component and handle Any Damage on the turret.

Multiplayer​

  • The AI controller runs on the server only.
  • The turret's aim (TurretRotation) replicates; the Animation Blueprint reads it on every machine.
  • Shots are a multicast: every machine spawns its own, unreplicated projectiles and plays the muzzle flash and sound.
  • The reset sound plays on every machine.

Your own turret model​

  1. Create a Blueprint child of ATurretPawn, or of B_TurretPawn to keep the effects and sounds.
  2. On MeshComponent, set your skeletal mesh and an Animation Blueprint that rotates the head and barrel from the pawn's TurretRotation (see ABP_Turret). TurretRotation is relative to the turret's base.
  3. Add sockets for the muzzle and, for two barrels, a left and right muzzle. Set their names in Muzzle Socket, Left Muzzle Socket and Right Muzzle Socket (defaults muzzle, muzzle_left, muzzle_right).
  4. Set AI Controller Class to B_TurretAIController or a child of it.

A single-barrel turret fires from Muzzle Socket. A dual-barrel turret fires from the left socket first and from the right one after DualBarrelShootDelay.

Your own projectile​

Create a Blueprint child of ATurretPlasmaProjectile (or of B_TurretProjectile). Its ProjectileMovementComponent has no gravity by default; raise Projectile Gravity Scale for a ballistic arc, but note that the lead calculation assumes a straight line. Set the new class as the turret's ProjectileClass.

Effects and sounds​

On the turret: ShootSound, ResetTurretSound, MuzzleFlashEffect and ProjectileEffect. Override SpawnShootFX for a custom muzzle effect. The muzzle flash receives the shot direction in its Direction variable.

Things to know​

  • Aiming assumes a target standing on the turret's floor. The turret aims at a Character's feet from its base, and the muzzle height lifts the shot into the capsule. Flying or small non-Character targets are overshot by about the muzzle height.
  • Dual barrels fire parallel. Both shots fly in the same direction, offset by the distance between the barrels.
  • Projectiles fly until they hit something. Give your projectile class an Initial Life Span if turrets fire into open space.