This document is about: QUANTUM 2
SWITCH TO

HFSM

Overview

The FPS Template relies on the Bot SDK addon for its AI features, specifically the HFSM, to build actions and decisions for the AI agents. This page will provide an overview of how the default HFSM is setup inside the FPS Template as well as cover the most important actions and decisions.

HFSM

When building an HFSM, the Idle state is commonly used as a starting and connecting point between the different states - e.g. once an agent has finished attacking, it returns to the Idle state before checking what it can do next. This approach, however, has a draw back; namely: the HFSM will stay in this transitional / dummy state for at least one tick before moving to the next possible one. Optimizations made in the FPS Template result in HFSMs not being executed every tick - for more details please refer to the Ticking and Optimization chapter. As a side effect of these optimizations the agent will stay, at least momentarily, in a dummy state which can be causing unwanted idle time. For this reason, the FPS Template example HFSM heavily makes use of transition sets. Transition sets help avoid duplicate transitions and help with the aforementioned idling issues by skipping dummy states during the decision process and executing the next action immediately. Thus instead of having, for example, Attack → Idle → Pickup the HFSM can directly transtion to the next state Attack → Pickup. More information on transition sets can be found in the Bot SDK manual.

fps template ai hfsm overview
FPS Template Overview of the Solider AI HFSM

The SoldierHFSM example has an Idle state but it acts only as a fallback state in case the agent has absolutely no other option.

Actions

SetWeaponRangeDestination

SetWeaponRangeDestination is the main action for setting an attack position. The attacker's weapon range is taken into consideration when performing this action. If RandomizeApproachAngle is enabled, angle intervals are used for a more believable position selection. This means the attacker will not only change its distance to the target but also attack angles resulting in changing positions from the left side of the target to the right side and vice versa within the pre-defined angle limits.

For performance reasons NavMesh line casts are performed to check if an enemy is in the line of sight of a new position instead of raycasts.

SetStrafeDestination

SetStrafeDestination is the action for setting a strafe's destination position. After performing this action, the AI agent's position will be moving from left to right and vice verse from target’s perspective. This action can be used to set the strafe min and max distance used to randomize strafing. The angle intervals are used to randomize the angles at which the agent is strafing.

SetWaypointDestination

SetWaypointDestination is used for wandering around the level using waypoint objects in the scene. The next waypoint destination is selected based on the distance and angle to the current waypoint; weights are used to prioritize one metric over the other. The SelectRandomFromFirst method will choose a random waypoint from the first N waypoints after they have been sorted by priority - this ensures agents provide a variety of behavior by not always taking the same path in the same situation.

SetRotationTypeAI

SetRotationTypeAI is the main action for setting an agent's rotation. The action does not set the rotation directly via HFSM; it sets a rotation type and the specific rotation behavior tied to this type is executed from the animation state. For more information on Rotation types please refer to the Rotation chapter.

SetFocusPointFromMemory

When a memory event is recorded, for example a weapon was fired, the AI agent should be able to look at the position where this event took place. The SetFocusPointFromMemory action sets the focus point to the location of the memory source. When the rotation type is set to FocusPoint, the agent will look towards this position. For an EnemyLost memory, a simple enemy position extrapolation based on the velocity can be applied. This ensures the agent will not look directly at the point where the enemy was last seen and adjust the position according to where the enemy is expected to be.

Decision

HasMemoryRecord

HasMemoryRecord is a basic decision for verifying whether the agent has recorded a certain memory. For example when the agent has an EnemyLost memory record, they can choose to switch to the Pursue state and chase the enemy.

Back to top