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
Hitboxin range - Supports warm-up delay and impact feedback
- Visually displays the laser using
LineRenderer
Fields
| Field | Type | Description |
|---|---|---|
laserSettings.line | LineRenderer | Visual representation of the beam. |
resolution | int | Number of spline points used for beam smoothness. |
radius | float | Width of the beam. |
snapRadius | float | Radius used to detect nearby Hitbox targets. |
maxLength | float | Max distance of the laser beam. |
affectedLayer | LayerMask | Defines 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
| Event | Description |
|---|---|
laserEvents.OnImpact(Vector3) | Invoked every frame with the laser’s impact point. |
Public Methods
| Method | Description |
|---|---|
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.OverlapCapsuleto detect targets near the beam path. - Picks the closest valid
Hitboxwithin thesnapRadius. - Uses a
CubicSplineto 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