Turret Projectiles & Customization
Turret Projectiles & Customization
Turrets in this system can use either physical projectiles or raycasts. This page explains how projectiles work and how to create your own.
π Two Modes of Fire
1. Projectile Mode
Spawns a physical object using a prefab.
Requires a
Rigidbody
and theTurretProjectile
script.Supports Directional (straight line) or Homing movement.
2. Raycast Mode
No physical bullet β instant hit is simulated via raycast.
The
TurretProjectile
still gets instantiated to handle hit VFX and custom logic.
π§© Required Setup (for custom projectiles)
Every projectile prefab must have:
β
TurretProjectile
componentβ
Rigidbody
(set touseGravity = false
)β Collider (usually a
SphereCollider
, set asisTrigger = true
)
These are added automatically if you use the menu: GameObject βΈ Turret βΈ Create Turret Projectile
π οΈ Key Settings (TurretProjectile)
Mode
Directional
(straight shot) or Homing
(tracks a target)
Speed
How fast the projectile travels (units/sec)
Life Time
Auto-destroys after this many seconds
Rotation Speed
How quickly the homing projectile can turn
Collision Layers
Which layers this projectile can hit
Hit Effect Prefab
Optional VFX spawned on impact
Hit Effect Lifetime
Time before hit effect is destroyed
β‘ Events
enemyHit(GameObject, float)
enemyHit(GameObject, float)
This UnityEvent is triggered when the projectile hits an enemy. You can use it to:
Play custom effects
Trigger animations
Apply extra logic to the hit object
π‘ Notes
Raycast projectiles simulate impact, but don't move β they rely on a fake visual trail if desired.
Physical projectiles should always use
Rigidbody.linearVelocity
, not physics forces.Homing mode uses
Transform.LookRotation
toward the target and adjusts over time.
π¦ Creating a Custom Projectile
Duplicate an existing projectile prefab
Replace the visual model (optional)
Adjust inspector values like speed, damage, etc.
Assign to your turretβs Projectile Prefab field
Done!
Or use the editor menu to auto-create one: GameObject βΈ Turret βΈ Create Turret Projectile
For advanced setups, you can subclass TurretProjectile
to extend behavior.
Last updated