Laser Guide
The LaserGuide steers the projectiles of a ProjectileBarrel toward a target. The secondary input turns the guide on and off for every projectile in flight. Each guided projectile needs a LaserFollower.
Add Component: Glowing Rifts > Misc > Laser Guide and Glowing Rifts > Misc > Laser Follower
Summary
This component:
- Listens for projectiles spawned by its barrel
- Gives every
LaserFollowerthe target while the guide is on - Toggles the guide and its laser object with the secondary input
Fields
| Field | Type | Description |
|---|---|---|
_target | Transform | Target the projectiles follow. |
_barrel | ProjectileBarrel | Barrel whose projectiles are guided. |
_laser | GameObject | Shown while the guide is on. |
Private Fields
| Field | Type | Description |
|---|---|---|
_controls | WeaponControls | Input used to toggle the guide. |
_laserActive | bool | Whether the guide is on. Starts on. |
_activeProjectiles | List<LaserFollower> | Guided projectiles in flight. |
Methods
| Method | Description |
|---|---|
Start() | Subscribes to the barrel’s projectileEvents.OnProjectileSpawned and to the ShootSecondary input. |
ToggleLaser() | Turns the guide on or off for all projectiles in flight. |
Behavior
- A spawned projectile with a
LaserFollowergets the target while the guide is on, and none while it is off. - Turning the guide off mid-flight makes the projectiles fly straight; turning it on again steers them back.
- Projectiles leave the list when their
OnImpactevent fires. Ones destroyed without an impact are dropped on the next toggle.
LaserFollower
The LaserFollower sits on the projectile. It flies forward and turns toward its target, and is destroyed when it touches the target.
| Member | Type | Description |
|---|---|---|
target | Transform | The transform to turn toward. null flies straight. |
_speed | float | Forward speed. |
_rotateSpeed | float | How fast it turns toward the target. |
Note
The projectile needs a Rigidbody. The follower turns off its gravity and drives its velocity.
Requirements
- Projectiles must have a
LaserFollowerand aRigidbody. - The barrel must be a
ProjectileBarrel.