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 LaserFollower the target while the guide is on
  • Toggles the guide and its laser object with the secondary input

Fields

FieldTypeDescription
_targetTransformTarget the projectiles follow.
_barrelProjectileBarrelBarrel whose projectiles are guided.
_laserGameObjectShown while the guide is on.

Private Fields

FieldTypeDescription
_controlsWeaponControlsInput used to toggle the guide.
_laserActiveboolWhether the guide is on. Starts on.
_activeProjectilesList<LaserFollower>Guided projectiles in flight.

Methods

MethodDescription
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 LaserFollower gets 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 OnImpact event 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.

MemberTypeDescription
targetTransformThe transform to turn toward. null flies straight.
_speedfloatForward speed.
_rotateSpeedfloatHow 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 LaserFollower and a Rigidbody.
  • The barrel must be a ProjectileBarrel.

See Also