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.
pelletsParticleSystem[]Particle systems to visualize each pellet path and impact.

Inherited Fields

See RaycastBarrel for:

  • _range, _layers, _damagePoints, _impacts, _OnHit

Public Methods

MethodDescription
override void Shoot()Fires multiple rays (one per pellet) with random spread. Each ray has its own hit logic and VFX.

Behavior

  • Loops through all pellets[]
  • Randomizes horizontal/vertical offset per pellet
  • Casts a Physics.Raycast from each pellet’s position and forward direction
  • On hit:
    • Applies damage via Hitbox.Hurt(DamageData)
    • Invokes _OnHit and plays that pellet’s particle system

Use Cases

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

Tip

Use different particle shapes or colors per pellet for rich visual feedback.

Note

Make sure each pellet has its own particle system object with unique transforms.

See Also