Triggerables System

The Triggerables system provides a foundation for creating triggerable modules of all kinds (such as weapons). You can bind inputs to triggerable modules both in the editor or give the player the capability to create trigger groups during the game.

Triggerables Manager

To fire triggerable objects on a vehicle such as weapons, the vehicle must have a Triggerables Manager component on the root transform.

This component will store all the triggerable items (objects with a Triggerable component) already on the vehicle, as well as any triggerable modules loaded onto the vehicle during gameplay, so that they can be accessed by input scripts to fire.

Triggerables are fired according to their trigger index - for example, by default, the left mouse fires Triggerable items on trigger index 0, and the right mouse fires on trigger index 1. You can change the trigger index on a Triggerable component to determine what input will fire it.

Triggerable

For something to be fired it must have a Triggerable component on it.

Trigger Index

You can change the trigger index of a Triggerable by changing the value in the inspector. By default, controls are set up so that primary weapons are trigger index 0 and secondary weapons on trigger index 1. However, you can change this during gameplay like so:

// Change trigger index to any value
myTriggerable.DefaultTriggerIndex = 1;

Trigger Mode

In the inspector of the Triggerable component, you can change the Fire Mode setting to create single shot, burst fire and fully automatic weapons.

Controlling A Triggerable

You can control a triggerable in code like so:

// Start triggering
myTriggerable.StartTriggering();

// Stop triggering
myTriggerable.StopTriggering();

// Trigger once
myTriggerable.TriggerOnce();

// Set trigger level (e.g. for beam weapons)
myTriggerable.SetTriggerLevel(0.5f);

// Stop firing and cancel any burst
myTriggerable.Cancel();

Player Triggerables Input

To give the player the ability to fire weapons, add a PlayerInput_InputSystem_TriggerablesControls component somewhere in the player hierarchy.

This component uses Unity's Input System. To modify the bindings, open up the General Input Asset object (search in the project tab and double click) and this will open Unity's Input System editor, where you can modify the weapon input.

The AI already has weapons input set up in its Spaceship Attack Behaviour component (for the Space Combat Kit) or the AI Controller (for the Mech Combat Kit).

Last updated