Shotgun Barrel

The ShotgunBarrel extends RaycastBarrel to simulate shotgun fire by casting multiple rays in random directions within a spread angle. Each ray acts like a pellet and can independently hit and damage targets.

Summary

This component:

  • Fires multiple raycast pellets per shot
  • Each pellet can hit and damage separate targets
  • Supports randomized spread via angles
  • Plays VFX using per-pellet particle systems

Fields

FieldTypeDescription
_spreadfloatMax angle (in degrees) for horizontal and vertical spread of each pellet.
_pelletsPerBulletintPellets each bullet (shell) splits into. A shot fires BulletsFired x _pelletsPerBullet pellets.
_pelletTraceParticleSystemParticle system that draws the pellet traces. One trace is emitted per pellet that hits.

Inherited Fields

See RaycastBarrel for:

  • _range, _layers, _impacts, hitEvents

Protected Methods

MethodDescription
override void FireRays()Fires _pelletsPerBullet rays per bullet with random spread. Each ray has its own hit logic and trace.

Behavior

  • For each bullet, takes that bullet’s spawn point
  • Randomizes horizontal/vertical offset per pellet within _spread
  • Casts each pellet with CastRay
  • On hit:
    • Applies the full per-bullet damage via Hitbox.Hurt(DamageData)
    • Invokes hitEvents.OnHit, spawns impacts and emits one trace particle toward the hit point

Use Cases

  • Shotguns
  • Scatterguns or burst rifles
  • Weapons firing in cone shapes with multiple tracers

Tip

Set the trace particle system’s start speed and lifetime so traces reach typical hit distances.

See Also