TopDown Engine - Getting Started Tutorial
In this tutorial you'll learn the basic steps of the AIBrain graph for TopDown Engine.
Last updated
In this tutorial you'll learn the basic steps of the AIBrain graph for TopDown Engine.
Last updated
Note: To get you started using the AI Brain Graph, you should first follow the Install instructions and check that everything is working.
First of all, look for the MinimalAI3D_Tutorial scene (and open it), that will serve as a starting point for this tutorial. Basically, it is the TopDown MinimalAI3D scene with all enemies removed (with the exception of PatrolAndMoveAI).
Open the AIs group to check the content: you will find the PatrolAndMoveAI prefab along with two other gameObjects (stripped out of all AI components): PatrolAndMoveAI_Generated and PatrolAndMoveAI_Pluggable.
To start working with the graph, you'll need to create an AI Brain Graph:
In the Project panel, right-click the mouse button and select Create > The Bit Cave > AI Brain Graph
Rename the newly created asset PatrolAndMoveBrain (or anything you deem appropriate)
Double-click on the asset to open the Editor
Select the PatrolAndMoveAI prefab in scene and look at the AI Brain, AI Actions and AI Decisions components: we want to replicate the same structure with the AI Brain Graph:
The AI Brain has two states: Patrolling and MoveTowardsTarget
While in Patrolling the character will perform an AIActionMovePatrol3D and an AIActionAimWeaponAtMovement action
While in MoveTowardsTarget the character will perform an AIActionMoveTowardsTarget3D and an AIActionAIMWeaponATMovement action
The chracters will exit the Patrolling state if the target is within range (AIDecisionDetectTargetRadius3D)
The character will not exit the MoveTowardsTarget state after a while
To create the AI Brain Graph we will need these nodes:
Two states
Two transistions
Three actions
One decision
First of all, let's create the two states:
Right click on the AI Brain graph canvas and choose AI > Brain State: this will create a state
Right click on the node header and choose Rename. Rename the state Patrolling and select Apply
Repeat the first two steps, creating another node called MoveTowardsTarget
On the Patrolling node, click the Set as starting state button: this will set the Patrolling node as the entry state in the character brain
Each state should always have a unique name
The Patrolling state has a single transition, so we are going to create it:
Right click on the Graph canvas and select AI > Transition: this will add a transition node
Click on the transitions output in Patrolling state and drag it to the Input element of the transition node
There's no decision for the MoveTowardsTarget state, so we won't need a transition.
The original character has a single decision, connected with the Patrolling state, so let's add it to the graph.
Right click on the graph canvas and select AI > Decision > 3D > Detect Target Radius
Set the Radius to 8
Set the Target Layer Mask to Player
Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding
Connect the Output element to the Decision input of the patrolling state AI Transition node
The swordsman has three actions, with one of them in common with both states: let's add them to the graph.
For the Patrolling state:
Right click on the graph canvas and select AI > Action > 3D > Move Patrol
Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding
Connect the Output element to the Actions input of the Patroling state node
Right click on the graph canvas and select AI > Action > Aim Weapon At Movement
Connect the Output element to the Actions input of the Patrolling state node
For the MoveTowardsTarget state:
Right click on the graph canvas and select AI > Action > 3D > Move Towards Target
Connect the Output element to the Actions input of the MoveTowardsTarget state node
You don't need to create a second Aim Weapon At Movement
Connect the Output element to the Actions input of the MoveTowardsTarget state node
The last step to complete the brain graph is to connect the transitions True/False states. In this case we only need the True one:
Connect the True State of the patrolling AI Transition to the States in input of the MoveTowardsTarget state
We are now ready to add the brain graph to a gameObject and generate all the TopDown Engine AI structure: we have two options for this.
The AI Brain Generator component adds a static brain structure to your character, just like you are used to do in TopDown Engine:
Enable the PatrolAndMoveAI_Generated gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Generator
Drag the PatrolAndMoveBrain we created above in the AI Brain Graph field
Click the Generate button and you will get the full working TopDown AI system for the PatrolAndMoveAI (try comparing it with the original prefab)
Once you are happy with your brain, you can safely remove the AI Brain Generator component as it is not used during gameplay
The AI Brain Pluggable generates all Corgi AI system at runtime from a list of brain graphs:
Enable the PatrolAndMoveAI_Pluggable gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Pluggable
Drag the PatrolAndMoveBrain in the AI Brain Graphs field: this is an array of elements, so you can add more than one (one will be chosen randomly at runtime)
Editor Play button and you should see the TopDown Engine AI Brain structure generated
The AI Brain Pluggable is an extension of the regular TopDown Engine AI Brain, so you'll have to keep it in your gameObject