Laser Barrel

The LaserBarrel is a type of Barrel that simulates continuous beam fire using a LineRenderer. It can apply damage to nearby targets, visually curves the beam, and supports a wind-up time 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
damagePointsintAmount of damage applied per hit.
_lineLineRendererVisual representation of the beam.
resolutionintNumber of spline points used for beam smoothness.
snapRadiusfloatRadius used to detect nearby Hitbox targets.
maxLengthfloatMax distance of the laser beam.
affectedLayerLayerMaskDefines which layers the beam can affect.
windUpTimefloatTime (in seconds) before the laser starts firing.

Events

EventDescription
OnImpact(Vector3)Invoked every frame with the laser’s impact point.
OnWindUpInvoked once when wind-up starts.

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.
override void Prepare(Action callback)Delays firing based on windUpTime.
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