Documentation‎ > ‎

4. Fire Controller

The Fire Controller automates the usage of a TargetTracker component on the same GameObject.. Read through the information in this section to gain an understanding of the many available options.

This section will familiarize you with the Editor interface and options so you can get started right away. More detail on how this system is implemented is provided in the FireController Code Reference section.

Interval
How often, in seconds, should the controller attempt to fire (trigger the OnFire event). The other options determine if the event is actually triggered when the countdown hits 0. If another option, such as Wait for Alignment, determines that it is still not time to fire, the interval counter will not reset, so the FireController will fire as soon as possible. FireControllers can also be forced to fire without waiting via the method FireImmediately.


Init Countdown at 0
If True, the Fire Controller will fire immediately once a target is available. Once it fires the first time, the timer will then be used from then on. This is ideal if you want a weapon to be able to fire immediately on-spawn, without "powering up", for example.


Wait for Alignment
If true, the controller will only fire if a target is directly in front of the GameObject. This is like adding the barrel of a gun. You can use animation or other systems to actually rotate the GameObject. For example, the Path-o-logical UnityConstraints package has a Smooth Look At Constraint that can handle turning to look at a target. This constraint is included with TargetPRO and is used in Example scenes..
Emitter
The transform used to determine the forward vector that is used for alignment (angle) calculations

Angle Tolerance
A mathematically perfect angle may never occur so a tolerance is used to provide an angle that is "good enough".  Too big and it won't look visually like it is waiting long enough to point at the target. Too small and it may never fire at all.

Flat Comparison
If false the actual angles will be compared for alignment (More precise. Emitter must point at target.) If true, only the direction matters. (Good when turning in a direction but perfect alignment isn't needed.)

Notify Targets
  • Off -  Do not notify anything. delegates can still be used for custom handling. This just means nothing will be sent directly to a Target and no projectile will be used. All of the event delegates will still behave as expected, so if you subscribe to the OnFire event, your function will be called when expected.
  • Direct - If a target is being hit, it will be notified immediately and passed a HitEffect struct so it can act accordingly. 
  • Pass To Projectile - OnFire, a projectile will be launched and passed this controllers effects. The projectile must then handle notification.  Use this when you want to set the effects on the launcher and pass them to the projectile.
  • Use Projectile Effects - OnFire, a projectile will be launched but this controllers effects will NOT be passed. The projectile's effects will be used instead. The projectile must then handle notification. Use this when you want to set the effects on the projectile to create a generic launcher. For example, the launcher can be a gun that fires every 4 seconds, but the ammunition determines the effects, such as an explosive round versus a regular round. This is especially useful if the player is deciding what ammo to load. In this case you would only need to change the "Ammo" reference (See Ammo below).

Ammo (Optional)
The prefab to spawn if "Notify Targets" (above) is set to use a projectile. This controller will simply spawn an instance of this prefab. It is up to the prefab to define its behavior. For example, you could add a script that, on Awake(), will launch itself as a Rigidbody in the direction it is spawned. Or a script which tracks its target and flies toward it, like a heat-seeking rocket. Or you could do nothing, add a Rigidbody, and let it simply drop on the ground.


Effect On Targets
Define the effect this fire controller will have on hit targets (ignored if "User Projectile Effects" is ON). You can define more than one, which is handy if you have a magic effect that will cause damage and slow down a target. This information is sent to targets when hit, or accessed via the API by other components.

The target should implement the logic to determine how to respond to the effects you define here. The reason for this is that each target may have abilities that modify the effect. For example, an enemy may have a resistance to a slow effect, or a friend may have a "buff" which increases a healing effect.

Here is a guide to using the GUI list features...
Debug Level
Set this to control the amount of information printed to the Unity Console to aid development.

Delegates

This component offers several event delegates (See the code reference for more detailed information) :
OnStart()
Triggered once, when when the targeting system starts up. This happens OnEnable(), which includes instanciation/spawning this component
OnUpdate()
Triggered each frame while the targeting system is active, no matter what.
OnTargetUpdate(List<Target> targets)
Triggered each frame while tracking a target. Supplies a list of targets; which / how many targets are provided, depends on the settings used.

OnIdleUpdate()
Triggered each frame when there is no target in range
OnFire(List<Target> targets)
Triggered when this FireController fires. When this happens, and which / how many targets are provided, depends on the settings used.

OnStop()
Runs once when when the targeting system is stopped. This happens OnDisable(), which includes destroying this component