Laser Barrel

The LaserBarrel is a type of Barrel that simulates continuous beam fire using a LineRenderer. It can apply damage to nearby targets, and visually curves the beam. Add a Spool to the same GameObject for a wind-up before activation.

Summary

This component:

  • Uses a spline-based beam that updates every frame
  • Applies damage to the nearest Hitbox in range
  • Supports warm-up delay and impact feedback
  • Visually displays the laser using LineRenderer

Fields

FieldTypeDescription
laserSettings.lineLineRendererVisual representation of the beam.
resolutionintNumber of spline points used for beam smoothness.
radiusfloatWidth of the beam.
snapRadiusfloatRadius used to detect nearby Hitbox targets.
maxLengthfloatMax distance of the laser beam.
affectedLayerLayerMaskDefines which layers the beam can affect.

All fields above except line are also on laserSettings. Damage per tick is rolled from the barrel’s config.damage.

Events

EventDescription
laserEvents.OnImpact(Vector3)Invoked every frame with the laser’s impact point.

Public Methods

MethodDescription
override void StartShooting()Enables laser beam and starts firing loop.
override void StopShooting()Disables laser beam.
override void Shoot()Applies damage to the closest target in path.
void SetImpactPosition(Transform target)Moves a target transform to the laser’s hit point.

Internal Logic

  • Uses Physics.OverlapCapsule to detect targets near the beam path.
  • Picks the closest valid Hitbox within the snapRadius.
  • Uses a CubicSpline to bend the beam between origin and destination.
  • Runs a coroutine to refresh the laser’s appearance and hit detection every frame.

Use Cases

  • Energy rifles
  • Mining lasers
  • Continuous fire weapons
  • Tactical scanning beams

See Also