Weapon System
Weapon
The Weapon component provides a standardized way of creating core weapon functionalities. It works together with the Triggerable component to manage the firing of one or more weapon units that make up the weapon.
Accessing Weapon Units
Each weapon is made up of one or more weapon units. You can add weapon units in the inspector, and access them in the list like so:
Firing Conditions
Firing conditions are basically boolean functions (functions that return True or False) that can be added from any class in a similar way to Unity Events. You can specify in the inspector of the Weapon component with the Evaluation Type whether the firing conditions must all be true (AND) or if only one needs to be true (OR) for the weapon to fire.
To add a firing condition, simply add an element to the Firing Conditions Conditions list in the inspector of the Weapon component, drag in an object, select the component, and select the boolean function on the component that must return True for the weapon to fire.
This enables you to set up any kind of scenario in which the weapon cannot fire.
Sequential/Simultaneous Firing
If the Weapon component has several Weapon Units, you can specify with the Multi Weapon Firing Mode in the inspector whether they should fire sequentially or simultaneously.
Resource Handlers
Weapon components feature a Resource Handlers list in which the weapon can add or subtract units from a Resource Container every time they are fired.
When you add an element to the list of Resource Handlers, you can specify with the Unit Resource Change field whether units are added or subtracted. A positive value means that amount will be added to the Resource Container (and can be used e.g. for heat production) and a negative value means that amount will be subtracted from the Resource Container (e.g. ammo depletion).
Weapon Info
The Weapon base class provides functions for obtaining key weapon info that is used for the loadout menu and can be used for any kind of HUD or information display.
Damage
Speed
Range
Fire Rate
These functions can be overridden in derived classes to provide accurate information for a specific weapon. You can access these values in code like so:
Aiming
Any weapon can be made to aim at a specific world position simply by calling a function like so:
In most cases, for non-turret weapons, these functions result in the spawn transforms of the weapon being rotated to point to the specified position, this is how the weapons fire at where the cursor is.
Triggering
The Weapon component relies on a Triggerable component for determining what it does when it is triggered, so check that out for more info. To trigger a weapon you can use the following functions:
Weapon Units
Since a weapon can be made up of multiple weapon units, the Weapon Unit component has very similar functionality to the Weapon component for aiming, triggering, and obtaining weapon info, however you usually would query weapon information and operate the weapon through the Weapon component.
Last updated