The move AI decides where a combatant will move to.
This can be used by all combatants except the directly controlled player, i.e. also for members of the player group. You can set up move AIs in Combatants > Move AIs.
If a combatant uses a move AI (and which is used as a default) is set up in the combatant’s Movement Settings, but can be overruled by components in the scene that actually add/spawn the combatant (e.g. in Combatant Spawners). Additionally, the event system and battle AI can change the used move AI of a combatant, as well as change the used mode or even set a target to move to.
You can see a basic use case of the move AI in game tutorial 30.
One thing to keep in mind with move AIs is that they only determine the position a combatant should move to. The actual movement is handled by the Move Component Settings of the move AI.
The move component settings handle the method used to move the combatant to the determined position. ORK Framework includes a simple Default movement component to get you started, but you should replace it with either using the Nav Mesh Agent (i.e. using Unity’s NavMesh) or a Custom component to implement your own movement solution (e.g. check the Poly|Nav 2D plugin).
You can set up using different speeds for the different modes of the move AI (e.g. hunting and fleeing). This can either use the combatant’s walk, run or sprint speeds (e.g. influenced by status effects), or a defined value.
For the combatant to be able to move toward or away from another combatant, it needs to be able to detect it. The Enemy Detection settings handle how the move AI’s user can detect enemy combatants and points of interest (more on them further down below).
Enemies can be detected upon Sight, Movement or when they’re within one of the user’s Combatant Triggers. Sight just requires the enemy to be within range and a defined angle to be detected (optionally using a raycast for line of sight checks), Movement additionally needs the enemy to actually move and not stand still.
When using Combatant Triggers, you can check only certain triggers via the tag and also only after the enemy has been within it for a certain amount of time – e.g. having a combatant trigger in front of the user detecting enemies immediately, but in the back only after several seconds.
You can also automatically detect the user’s group/individual targets, even if they’d otherwise not be detected.
Target Position Checks
If the move AI has a target (e.g. hunting another combatant, following its leader), the position of the target will be checked frequently and forwarded to the movement component. You can define several intervals based on different distances, the combatant will move to the position of the last check. The interval between two checks should decrease as the combatant gets nearer to the target.
A detected target can also be lost if it is no longer detected. The Target Lost Interval defines the time until a target is considered lost – this can either keep the combatant moving to the last known position, or still update the target’s position via the defined check intervals.
The move AI operates in different modes – this can either happen automatically via the Auto mode, or by locking the move AI to use only a defined Use Mode. The use mode can also be changed via combatant spawners, battle AI and the event system.
When in Auto mode, the move AI will decide the used mode based on the detected target and the different modes’ conditions.
Detection Game Events
Hunt, flee, caution and protection modes can use game events when first detecting a target to use. The detection game event will use the the move AI’s user as Event Object actor and the detected target as Starting Object actor.
This can be used to e.g. perform an animation, play an audio clip or show a short dialogue. You can also use it to implement a custom system – it uses a regular game event, so you can do everything you want.
When no target is detected, the move AI will be in Waypoint mode (Idle use mode). The combatant will move from waypoint to waypoint – they can either be random positions (using Enable Random Patrol) or defining specific waypoints via the Combatant Spawner or Add Combatant components used to add the combatant to the scene.
Between waypoints, the combatant can optionally use an Idle Behaviour. An idle behaviour uses a Move Event to perform a short animation or wait time. Once the move event finished, the combatant will move to the next waypoint.
Points of interest can only be detected in Waypoint mode (more on POIs further down below).
Combatants that are not the leader of their group can follow their leader (and also move out of the way). The combatant can also completely stop following waypoints or hunting targets, or still perform these tasks, but follow the leader when out of follow range.
When getting to far away from the leader, the combatant can also automatically respawn beside it.
The combatant will hunt the detected target – i.e. move toward it until reaching a defined range to the target. Hunting can optionally be limited to a defined range within the combatant’s spawn position, moving back to it when getting out of range.
When using the optional Stop Range to stop at a certain distance before reaching the target, you can use a Stop Angle to e.g. try to move toward the back of the target.
Hunting can be limited to certain conditions, beside simple level and group size checks of the target, you can also use more complex status requirements, checking user and/or target for conditions. E.g. only hunting while the user’s HP are above 50% and the target’s level isn’t over 5 levels higher than the user’s level.
The combatant will flee from the detected target, moving away from it. The optional Prevent Cornered setting will try to prevent the combatant from getting stuck or driven into a corner by moving into random directions when no longer being able to move, even if it’s toward the target.
Like hunting, fleeing can also be limited to a defined range of the combatant’s spawn position and certain conditions.
The Caution mode is a mix between hunting and fleeing. The combatant will try to stay within a certain distance to the target, moving toward it when out of range and moving away from it when the target comes within a Critical range. This mode is best used for combatants using ranged attacks.
Like hunting, caution can also be limited to a defined range of the combatant’s spawn position and certain conditions.
The combatant will try to protect a member of its own group from a detected target. This is done by moving the combatant between the target and the group member. The combatant can either move up to the detected target or the protected group member, keeping a defined distance from them.
Like hunting, protection can also be limited to a defined range of the combatant’s spawn position and certain conditions. The conditions are separated by the detected target and the protected group member, e.g. only protecting weak ranged members like mages.
Points of Interest
A combatant can detect points of interest (POI) while moving between waypoints (i.e. no detected target). They’re set up in your scene using Point Of Interest components, which can use an optional game event once the combatant reaches the POI. The event uses the combatant as Event Object actor and the POI as Starting Object actor. You can e.g. use this to play an animation or show a dialogue, or do whatever else you want.
The component also defines at which distance the combatant will stop, as well as the speed at which the combatant will move toward it. Additionally, the POI can have a Detection Tag, limiting who can detect it.
The move AI can be set up to use points of interest in the Waypoint Settings, where you can also define tags that can be detected by the combatant (without a defined tag, the combatant will be able to detect all POIs). The actual detection of POIs is handled just like detecting enemies, i.e. via the Enemy Detection settings.