Laser Barrel
The LaserBarrel
is a unique implementation of the base barrel system that fires a continuous laser beam using Unity’s LineRenderer
. It’s ideal for sci-fi weapons where the bullets are beam energy.
✅ Ideal For
- Laser rifles
- Beam weapons
- Sci-fi turrets
- Mining or cutting tools
⚙️ How it works
The laser barrel simulates a curved beam rendered in real-time using a LineRenderer
. This beam is dynamically shaped with the help of a CubicSpline algorithm that gives it a natural arc.
- The laser snaps to the closest target based on a configurable Snap Radius
- Impacts are processed once a valid object is hit on the specified Affected Layer
- Beam rendering and logic begin after an optional Wind Up Time
- the laser is continuous but it consumes hypothetical bullets from the magazine.
Note
Each bullet consumed will inflect the damage point on the target.
📐 Additional Settings
Aside from the base barrel logic, the laser barrel includes these unique options highlighted in the red box in the image below
Field | Description |
---|---|
Damage Points | Amount of damage applied when the laser hits a target |
Line | Reference to the LineRenderer component that renders the laser beam |
Resolution | Number of spline points used to generate the beam curve |
Snap Radius | Radius within which the beam will snap to valid targets |
Max Length | Maximum distance the laser can reach if nothing is hit |
Affected Layer | Determines what layers the laser can affect (damage or snap to) |
Wind Up Time | Time delay before the laser activates after input is triggered |
On Impact (Vector3) | Called when the laser successfully hits a target |
On Wind Up () | Triggered once the wind-up period is complete, before the laser activates |
🌀 Curved Laser with Cubic Spline
The LaserBarrel
uses a Cubic Spline algorithm to simulate realistic beam curvature. This curve is recalculated each frame to give the laser a fluid, reactive feel. The spline adapts to target poisition if they are still within radius
Tip
Adjusting Resolution
and gives you fine control over laser quality vs performance.