TopDown Engine - Getting Started Tutorial

In this tutorial you'll learn the basic steps of the AIBrain graph for TopDown Engine.

Note: To get you started using the AI Brain Graph, you should first follow the Install instructions and check that everything is working.

The Tutorial Scene

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).

  1. 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.

Creating the AI Brain Graph

To start working with the graph, you'll need to create an AI Brain Graph:

  1. In the Project panel, right-click the mouse button and select Create > The Bit Cave > AI Brain Graph

  2. Rename the newly created asset PatrolAndMoveBrain (or anything you deem appropriate)

  3. Double-click on the asset to open the Editor

The PatrolAndMoveAI Brain Structure

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

Creating the States

First of all, let's create the two states:

  1. Right click on the AI Brain graph canvas and choose AI > Brain State: this will create a state

  2. Right click on the node header and choose Rename. Rename the state Patrolling and select Apply

  3. Repeat the first two steps, creating another node called MoveTowardsTarget

  4. 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

Adding Transitions

The Patrolling state has a single transition, so we are going to create it:

  1. Right click on the Graph canvas and select AI > Transition: this will add a transition node

  2. 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.

Adding AI Decisions

The original character has a single decision, connected with the Patrolling state, so let's add it to the graph.

  1. Right click on the graph canvas and select AI > Decision > 3D > Detect Target Radius

  2. Set the Radius to 8

  3. Set the Target Layer Mask to Player

  4. Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding

  5. Connect the Output element to the Decision input of the patrolling state AI Transition node

Adding AI Actions

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:

  1. Right click on the graph canvas and select AI > Action > 3D > Move Patrol

    1. Set the Obstacle Mask to Obstacles, ObstaclesDoors, NoPathfinding

    2. Connect the Output element to the Actions input of the Patroling state node

  2. Right click on the graph canvas and select AI > Action > Aim Weapon At Movement

    1. Connect the Output element to the Actions input of the Patrolling state node

For the MoveTowardsTarget state:

  1. Right click on the graph canvas and select AI > Action > 3D > Move Towards Target

    1. Connect the Output element to the Actions input of the MoveTowardsTarget state node

  2. You don't need to create a second Aim Weapon At Movement

    1. Connect the Output element to the Actions input of the MoveTowardsTarget state node

Connecting Transitions

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:

  1. Connect the True State of the patrolling AI Transition to the States in input of the MoveTowardsTarget state

Generating the Character AIBrain System

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.

AI Brain Generator

The AI Brain Generator component adds a static brain structure to your character, just like you are used to do in TopDown Engine:

  1. Enable the PatrolAndMoveAI_Generated gameObject

  2. Click the Add Component button and select The Bit Cave > AI > AI Brain Generator

  3. Drag the PatrolAndMoveBrain we created above in the AI Brain Graph field

  4. 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

AI Brain Pluggable

The AI Brain Pluggable generates all Corgi AI system at runtime from a list of brain graphs:

  1. Enable the PatrolAndMoveAI_Pluggable gameObject

  2. Click the Add Component button and select The Bit Cave > AI > AI Brain Pluggable

  3. 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)

  4. 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

Last updated