Use combatant triggers for physical detection of combatants.
Combatant Trigger Components #
Combatant Trigger components are used to keep track of combatants while they’re within the trigger’s bounds.
They require a collider (2D or 3D) used as trigger (with Is Trigger enabled) – to be able to register combatants. The combatants also need to have a collider and a rigidbody to enable physics interaction between them and the trigger.
You can use combatant triggers on their own or added to the game objects of your combatants (e.g. on their prefab). When they’re added to a combatant, the combatant itself is excluded from being detected by the combatant triggers.
Additionally, combatant triggers also know how long a combatant has been within them – e.g. this can be used to only detect targets for the move AI when they are in the trigger for a defined mount of time.
Add tags to combatant triggers to be able to identify different triggers.
E.g. use the tag front for a combatant trigger in the front of the combatant and tag for a trigger in the back of the combatant.
Adding Combatant Triggers #
Combatant Trigger components can be added to any game object, either on their own or on a combatant’s game object. You’ll usually add them to a combatant’s prefab, but can also be added in-game, e.g. by spawning them as a prefab and parenting them to a combatant. You can also add them as a child object of the combatant’s game object.
Keep in mind that you also need a collider set up as trigger (Is Trigger enabled).
You can easily create a ready-to-use combatant trigger via the scene hierarchy context menu: ORK Framework > Combatant > Combatant Trigger (2D and 3D variants available)
The scene wizard can also create new combatant trigger game objects and add combatant trigger components to existing game objects (2D and 3D variants available).
Using Combatant Triggers #
Combatant triggers can be used in different functionality of ORK.
Battle AI #
The battle AI can select targets that are in the user’s combatant triggers.
You can also check for combatants that are in a combatant trigger for a defined amount of time.
Learn more about the battle AI in this documentation.
Move AI #
The move AI’s enemy detection can use combatants that are within the user’s combatant triggers.
Optionally this can be limited to combatants that are within the trigger for a defined amount of time.
E.g. immediately detect targets that enter a front combatant trigger, but detect targets in a back trigger only after 2 seconds.
Learn more about the move AI in this documentation.
Battle Ranges #
Battle ranges are used for use range and affect range target selection in abilities and items.
They can use combatant triggers to select targets, optionally limited to combatants that are within the trigger for a defined amount of time.
E.g. an ability should target all enemies in a 5 world units long area in front of the user.
Set up a combatant trigger for that area and use it’s tag for the battle range.
Learn more about battle ranges in this documentation.
Schematics can check if a combatant is within a combatant trigger (e.g. In Combatant Trigger or Combatant Trigger Time nodes) and use combatants in combatant triggers as selected data (Select Combatant Trigger node).
The schematic nodes can use both combatant triggers added to combatants or set up on their own.
You can also access the combatant triggers of a combatant via scripting:
List<CombatantTriggerComponent> triggers = combatant.Object.Triggers;
The combatant is an instance of the Combatant class, i.e. a combatant in your game.
The Combatant Trigger component has different functions available to get or check combatants within the trigger, check tags, etc.
For using combatant triggers of game objects, you can use the regular Unity functionality to get the CombatantTriggerComponent component, e.g.:
CombatantTriggerComponent triggers = gameObject.GetComponentsInChildren<CombatantTriggerComponent>();