|
1 | 1 | # First Steps with Ninja Bot |
2 | | -<primary-label ref="bot"/> |
| 2 | +<primary-label ref="bot"/> |
| 3 | + |
| 4 | +This page guides you through the first steps for **Ninja Bot**. Make sure to check the [**Bot Setup**](bot_setup.md) |
| 5 | +instructions before continuing. |
| 6 | + |
| 7 | +The following steps aim to provide **a functional AI agent that can roam, detect the player, and chase a sensed target**. |
| 8 | + |
| 9 | +This page uses a simple behavior with three states: **Idle**, **Roam**, and **Chase**. The main trigger between these |
| 10 | +states is whether the player is sensed or not. |
| 11 | + |
| 12 | +It is recommended that your **Gameplay Debugger** is configured, so you can inspect the Bot's perception data and evaluate |
| 13 | +its active AI states during gameplay. |
| 14 | + |
| 15 | +## Perception Configuration |
| 16 | + |
| 17 | +Ninja Bot uses a **Perception Sense Profile** to define how bots sense the world. For this first setup, we will create a |
| 18 | +simple Sight configuration that allows the bot to detect the player. |
| 19 | + |
| 20 | +<procedure title="Create the Perception Configuration" collapsible="true" default-state="expanded"> |
| 21 | + <step> |
| 22 | + <p>In your Perception Data folder, create a new <b>Perception Sense Profile</b> using the Content Browser contextual menu: <b>Ninja Bear Studio</b> → <b>Ninja Bot</b> → <b>Sense Profile</b>.</p> |
| 23 | + </step> |
| 24 | + <step> |
| 25 | + <p>Add the <b>Sight</b> sense to the list of senses. Configure <b>Sight Radius</b> to <code>1200</code> and <b>Lose Sight Radius</b> to <code>1400</code>.</p> |
| 26 | + </step> |
| 27 | + <step> |
| 28 | + <p>Mark Enemies, Neutrals, and Friendlies in <b>Detection by Affiliation</b>.</p> |
| 29 | + <note>For now, no <b>Affiliation</b> or <b>Team Attitude</b> is configured. Once we complete that setup, we will revisit this configuration.</note> |
| 30 | + </step> |
| 31 | + <step> |
| 32 | + <p>Set <b>Sight</b> as the <b>Dominant Sense</b>.</p> |
| 33 | + <tip>A dominant sense is <b>always required</b>, even if only a single sense is configured in the Perception Sense Profile.</tip> |
| 34 | + </step> |
| 35 | + <step> |
| 36 | + <p><img src="bot_guide_perception_sense_profile.png" alt="Perception Sense Profile" width="780" border-effect="line"/></p> |
| 37 | + </step> |
| 38 | +</procedure> |
| 39 | + |
| 40 | +## Roaming Query |
| 41 | +<secondary-label ref="optional"/> |
| 42 | +<secondary-label ref="recommended"/> |
| 43 | + |
| 44 | +The roaming behavior uses an **Environment Query** to find random reachable locations from the Navigation Mesh. |
| 45 | + |
| 46 | +> **Demonstration Step** |
| 47 | +> |
| 48 | +> The roaming behavior is included for demonstration and completeness, but it does not involve any Ninja Bot-specific setup. |
| 49 | +{style="tip"} |
| 50 | + |
| 51 | +<procedure title="Create the Roaming Environment Query" collapsible="true" default-state="expanded"> |
| 52 | + <step> |
| 53 | + <p>Create an <b>Environment Query</b> that retrieves random locations from the Navigation Mesh.</p> |
| 54 | + </step> |
| 55 | + <step> |
| 56 | + <p>Add a <b>Pathing Grid Generator</b> with <b>Grid Half Size</b> set to <code>1000</code> and <b>Space Between</b> set to <code>100</code>.</p> |
| 57 | + <p><img src="bot_guide_eqs_roam_generator.png" alt="EQS, Roam Generator" width="780" border-effect="line"/></p> |
| 58 | + </step> |
| 59 | + <step> |
| 60 | + <p>Add a <b>Distance Test</b> with <b>Float Value Min</b> set to <code>300</code> and <b>Float Value Max</b> set to <code>1200</code>.</p> |
| 61 | + <p><img src="bot_guide_eqs_roam_test_distance.png" alt="EQS, Distance Test" width="780" border-effect="line"/></p> |
| 62 | + </step> |
| 63 | +</procedure> |
| 64 | + |
| 65 | +## AI Logic |
| 66 | + |
| 67 | +Ninja Bot can expose perception and awareness data to either **Behavior Trees** or **State Trees**. Choose the option that |
| 68 | +matches the decision system used by your project. |
| 69 | + |
| 70 | +<tabs group="brain_type"> |
| 71 | +<tab title="Behavior Tree" group-key="bt"> |
| 72 | + |
| 73 | +<!-- BEGIN: BEHAVIOR TREE CONFIGURATION --> |
| 74 | + |
| 75 | +<procedure title="Create the Blackboard" collapsible="true" default-state="expanded"> |
| 76 | + <step> |
| 77 | + <p>In your AI folder, create a new <b>Blackboard</b> that will be used to store contextual data available to the AI agent.</p> |
| 78 | + </step> |
| 79 | + <step> |
| 80 | + <p>Create an entry for <b>SensedActor</b>, setting the <b>Key Type</b> to <code>Object</code> and the <b>Base Class</b> to <code>Actor</code>. Create a new <b>Entry Category</b> named <b>Perception</b>.</p> |
| 81 | + <p><img src="bot_guide_blackboard_sensed_actor.png" alt="Blackboard, Sensed Actor" width="780" border-effect="line"/></p> |
| 82 | + </step> |
| 83 | + <step> |
| 84 | + <p>Create three new <b>float</b> Key Types: <b>CandidateScore</b>, <b>NormalizedCandidateScore</b>, and <b>AccumulatedAwareness</b>. Add them to the <b>Perception</b> category.</p> |
| 85 | + </step> |
| 86 | + <step> |
| 87 | + <p>Create an entry for <b>AwarenessLevel</b>, setting the <b>Key Type</b> to <code>Enum</code>. Set the <b>Enum Name</b> to <code>EBotPerceptionAwarenessLevel</code>. Add this entry to the <b>Perception</b> category.</p> |
| 88 | + <p><img src="bot_guide_blackboard_awareness_level.png" alt="Blackboard, Awareness Level" width="780" border-effect="line"/></p> |
| 89 | + <note>When setting the Enum Name, make sure the <b>Enum Type</b> is correctly assigned automatically and the <b>Default Value</b> is set to <code>Unaware</code>.</note> |
| 90 | + </step> |
| 91 | + <step> |
| 92 | + <p>Create three new <b>Vector</b> Key Types: <b>FirstPerceivedLocation</b>, <b>CurrentTargetLocation</b>, and <b>LastKnownLocation</b>. Add them to the <b>Perception</b> category.</p> |
| 93 | + </step> |
| 94 | + <step> |
| 95 | + <p>Create one additional <b>Vector</b> Key Type, <b>RoamLocation</b>. Add it to a new category named <b>Roam</b>.</p> |
| 96 | + </step> |
| 97 | +</procedure> |
| 98 | + |
| 99 | +<procedure title="Create the Behavior Tree" collapsible="true" default-state="expanded"> |
| 100 | + <step> |
| 101 | + <p>Create a <b>Behavior Tree</b> and assign the <b>Blackboard</b> to it.</p> |
| 102 | + </step> |
| 103 | + <step> |
| 104 | + <p>From the Root node, create a <b>Selector</b> composite node and add the <b>Update Perception Service</b> to it. Match each property to the correct <b>blackboard key</b>.</p> |
| 105 | + <p><img src="bot_guide_behavior_tree_perception_service.png" alt="Behavior Tree, Update Perception Service" width="780" border-effect="line"/></p> |
| 106 | + </step> |
| 107 | + <step> |
| 108 | + <p>From the top Selector node, create a <b>Sequence</b> composite node for <b>Combat</b>. Add a <b>Blackboard Decorator</b> to check whether the <b>SensedActor</b> key is set. This Decorator should be configured to <b>abort both itself and lower priority nodes</b>.</p> |
| 109 | + <p><img src="bot_guide_behavior_tree_combat_branch_01.png" alt="Behavior Tree, Combat Branch 1" width="780" border-effect="line"/></p> |
| 110 | + </step> |
| 111 | + <step> |
| 112 | + <p>Add a <b>Move To</b> Task, using the <b>SensedActor</b> key as the <b>Target Location</b> and an <b>Acceptable Radius</b> of <code>50</code>. Add an <b>Is At Location</b> decorator using the same parameters, followed by a <b>Force Success</b> decorator. Lastly, add a <b>Wait</b> task set to <code>1 second</code> with a <b>Random Deviation</b> of <code>0.2</code>.</p> |
| 113 | + <p><img src="bot_guide_behavior_tree_combat_branch_02.png" alt="Behavior Tree, Combat Branch 2" width="780" border-effect="line"/></p> |
| 114 | + </step> |
| 115 | + <step> |
| 116 | + <p>From the top Selector node, create another <b>Sequence</b> composite node for <b>Roam</b>. Add a <b>Run EQS Query</b> task using the Environment Query created earlier, and configure it to write its result to the <b>RoamLocation</b> key. Add another <b>Move To</b> task using the <b>RoamLocation</b> key as the <b>Target Location</b>.</p> |
| 117 | + <p><img src="bot_guide_behavior_tree_roam_branch.png" alt="Behavior Tree, Roam Branch" width="780" border-effect="line"/></p> |
| 118 | + </step> |
| 119 | + <step> |
| 120 | + <p>Complete the Behavior Tree with another <b>Sequence</b> composite node for <b>Idle</b>. Add a <b>Wait</b> task set to <code>5 seconds</code>.</p> |
| 121 | + <p><img src="bot_guide_behavior_tree_idle_branch.png" alt="Behavior Tree, Idle Branch" width="780" border-effect="line"/></p> |
| 122 | + </step> |
| 123 | +</procedure> |
| 124 | + |
| 125 | +<!-- END: BEHAVIOR TREE CONFIGURATION --> |
| 126 | + |
| 127 | +</tab> |
| 128 | +<tab title="State Tree" group-key="st"> |
| 129 | + |
| 130 | +<!-- BEGIN: STATE TREE CONFIGURATION --> |
| 131 | + |
| 132 | +<procedure title="Create the State Tree" collapsible="true" default-state="expanded"> |
| 133 | + <step> |
| 134 | + <p>Create a State Tree using the <b>State Tree AI Component</b> Schema.</p> |
| 135 | + </step> |
| 136 | + <step> |
| 137 | + <p>Add the <b>Update Perception</b> evaluator.</p> |
| 138 | + <p><img src="bot_guide_state_tree_perception_evaluator.png" alt="State Tree, Update Perception Evaluator" width="780" border-effect="line"/></p> |
| 139 | + </step> |
| 140 | + <step> |
| 141 | + <p>From the Root node, add a <b>Child State</b> named <b>Combat</b>. Add an <b>Object Is Valid</b> Enter Condition, checking <code>UpdatePerception.SensedActor</code>.</p> |
| 142 | + <p><img src="bot_guide_state_tree_combat_state_01.png" alt="State Tree, Combat State 1" width="780" border-effect="line"/></p> |
| 143 | + </step> |
| 144 | + <step> |
| 145 | + <p>From the Combat state, add a <b>Child State</b> named <b>Move to Target</b>. Add a <b>Distance Compare</b> Enter Condition comparing the <b>Bot</b> and <b>Target</b> locations, a <b>Move To</b> task targeting <code>UpdatePerception.SensedActor</code>, and a <b>State Completed</b> transition to the <b>Next State</b>.</p> |
| 146 | + <p><img src="bot_guide_state_tree_combat_state_02.png" alt="State Tree, Combat State 2" width="780" border-effect="line"/></p> |
| 147 | + </step> |
| 148 | + <step> |
| 149 | + <p>Add another state named <b>Wait</b>. Add a <b>Delay</b> task with a <b>Duration</b> of <code>1.0</code> and a <b>Random Deviation</b> of <code>0.2</code>.</p> |
| 150 | + <p><img src="bot_guide_state_tree_combat_state_03.png" alt="State Tree, Combat State 3" width="780" border-effect="line"/></p> |
| 151 | + </step> |
| 152 | + <step> |
| 153 | + <p>From the Combat state, add a <b>Sibling State</b> named <b>Roam</b>. Create a <b>Vector Parameter</b> named <b>Roam Location</b>.</p> |
| 154 | + <p><img src="bot_guide_state_tree_roam_state_01.png" alt="State Tree, Roam State 1" width="780" border-effect="line"/></p> |
| 155 | + </step> |
| 156 | + <step> |
| 157 | + <p>From the Roam state, add a <b>Child State</b> named <b>Find Location</b>. Add a <b>Run EQS Query</b> task, bind the <b>Result</b> to the <b>Roam Location</b> parameter, bind the <b>Query Owner</b> to the <b>Context Actor</b>, and set the <b>Query Template</b>. Add an <b>On State Completed</b> transition to <b>Next State</b>.</p> |
| 158 | + <p><img src="bot_guide_state_tree_roam_state_02.png" alt="State Tree, Roam State 2" width="780" border-effect="line"/></p> |
| 159 | + </step> |
| 160 | + <step> |
| 161 | + <p>Add another state named <b>Move to Location</b>, and from the <b>Roam</b> state add another sibling named <b>Idle</b>. For <b>Move to Location</b>, add a <b>Move To</b> task and bind the <b>AI Controller</b> from the <b>Context</b>, and the <b>Destination</b> to <code>Parameters.RoamLocation</code>. Add an <b>On State Completed</b> transition to <b>Idle</b>.</p> |
| 162 | + <p><img src="bot_guide_state_tree_roam_state_03.png" alt="State Tree, Roam State 3" width="780" border-effect="line"/></p> |
| 163 | + </step> |
| 164 | + <step> |
| 165 | + <p>From the Idle state, add a <b>Child State</b> named <b>Wait</b>. Add a <b>Delay</b> task with a <b>Duration</b> of <code>5.0</code>.</p> |
| 166 | + <p><img src="bot_guide_state_tree_idle_state.png" alt="State Tree, Idle" width="780" border-effect="line"/></p> |
| 167 | + </step> |
| 168 | +</procedure> |
| 169 | + |
| 170 | +<!-- END: STATE TREE CONFIGURATION --> |
| 171 | + |
| 172 | +</tab> |
| 173 | +</tabs> |
| 174 | + |
| 175 | +## Bot Setup Data |
| 176 | + |
| 177 | +The **Bot Setup Data Asset** connects the bot's perception configuration with the decision system used by the AI Controller. |
| 178 | + |
| 179 | +<tabs group="brain_type"> |
| 180 | +<tab title="Behavior Tree" group-key="bt"> |
| 181 | + |
| 182 | +<!-- BEGIN: BOT SETUP WITH BEHAVIOR TREE --> |
| 183 | + |
| 184 | +<procedure title="Create the Bot Setup" collapsible="true" default-state="expanded"> |
| 185 | + <step> |
| 186 | + <p>In your Bot Setup Data folder, create a new <b>Bot Setup</b> using the Content Browser contextual menu: <b>Ninja Bear Studio</b> → <b>Ninja Bot</b> → <b>Bot Setup</b>.</p> |
| 187 | + <tip>Bot Setup assets are <b>Primary Assets</b> and must be placed in a folder registered with the <a href="asset_manager.md"><b>Asset Manager</b></a>.</tip> |
| 188 | + </step> |
| 189 | + <step> |
| 190 | + <p>Set the <b>Brain Type</b> to <b>Behavior Tree</b> and assign your Behavior Tree asset.</p> |
| 191 | + <p><img src="bot_guide_setup_basic_bt.png" alt="Bot Setup with Behavior Tree" width="780" border-effect="line"/></p> |
| 192 | + </step> |
| 193 | +</procedure> |
| 194 | + |
| 195 | +<!-- END: BOT SETUP WITH BEHAVIOR TREE --> |
| 196 | + |
| 197 | +</tab> |
| 198 | +<tab title="State Tree" group-key="st"> |
| 199 | + |
| 200 | +<!-- BEGIN: BOT SETUP WITH STATE TREE --> |
| 201 | + |
| 202 | +<procedure title="Create the Bot Setup" collapsible="true" default-state="expanded"> |
| 203 | + <step> |
| 204 | + <p>In your Bot Setup Data folder, create a new <b>Bot Setup</b>, using the Content Browser contextual menu: <b>Ninja Bear Studio</b> → <b>Ninja Bot</b> → <b>Bot Setup</b>.</p> |
| 205 | + <tip>Bot Setup assets are <b>Primary Assets</b> and must be placed in a folder registered with the <a href="asset_manager.md"><b>Asset Manager</b></a>.</tip> |
| 206 | + </step> |
| 207 | + <step> |
| 208 | + <p>Set the <b>Brain Type</b> to <b>State Tree</b> and add your State Tree asset.</p> |
| 209 | + <p><img src="bot_guide_setup_basic_st.png" alt="Bot Setup with State Tree" width="780" border-effect="line"/></p> |
| 210 | + </step> |
| 211 | +</procedure> |
| 212 | + |
| 213 | +<!-- END: BOT SETUP WITH STATE TREE --> |
| 214 | + |
| 215 | +</tab> |
| 216 | +</tabs> |
| 217 | + |
| 218 | +## Bot Character |
| 219 | + |
| 220 | +The Bot Character provides the Bot Setup Data and uses the Ninja Bot AI Controller. |
| 221 | + |
| 222 | +<procedure title="Create the Bot Character" collapsible="true" default-state="expanded"> |
| 223 | + <step> |
| 224 | + <p>Create a new <b>Character</b> and add the <b>Bot Setup Provider Interface</b>.</p> |
| 225 | + <p><img src="bot_guide_character_bot_interface.png" alt="Adding the Bot Setup Provider Interface" width="780" border-effect="line"/></p> |
| 226 | + </step> |
| 227 | + <step> |
| 228 | + <p>Double-click <code>GetBotSetupData</code> from the list of Interface Functions. Drag from the <b>Return Value</b> and <b>Promote it to a Variable</b>. Set the Bot Setup as its <b>default value</b>.</p> |
| 229 | + <p><img src="bot_guide_character_setup_data.png" alt="Configuring the Bot Setup data" width="780" border-effect="line"/></p> |
| 230 | + </step> |
| 231 | + <step> |
| 232 | + <p>In the <b>Character Defaults</b>, locate the <b>AI Controller Class</b> and set it to <code>NinjaBotAIController</code>.</p> |
| 233 | + <p><img src="bot_guide_character_bot_controller.png" alt="Configuring the Bot Controller" width="780" border-effect="line"/></p> |
| 234 | + </step> |
| 235 | +</procedure> |
| 236 | + |
| 237 | +## Next Steps |
| 238 | + |
| 239 | +At this point, you should have a Bot that **roams around the environment until it detects the player**. Once the player |
| 240 | +is sensed, the Bot transitions into a chase behavior and **actively pursues the target**. |
| 241 | + |
| 242 | +From here, you can: |
| 243 | + |
| 244 | +- Learn more about [**Perception and Awareness**](bot_perception_and_awareness.md). |
| 245 | +- Configure [**Patrol Points**](bot_patrol_paths.md). |
| 246 | +- Integrate [**Ninja Factions**](fct_overview.md) for team-aware perception. |
| 247 | +- Extend the AI logic using Behavior Trees or State Trees. |
0 commit comments