Use combatant triggers for physical detection of combatants.
Combatant Trigger Components #
Combatant Trigger components are added to the prefabs of your combatants and are used to keep track of other combatants while they’re within their bounds.
They require a collider (2D or 3D) used as trigger (with Is Trigger enabled) – to be able to register combatants, the other combatants also need to have a collider and a rigidbody to enable physics interaction.
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 for a defined mount of time in the combatant trigger.
Tags #
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 need to be added to the game object of a combatant. 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 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 add 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 #
Schematics can check if a combatant is within another combatant’s combatant trigger and use combatants in combatant triggers as selected data.
Scripting #
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.