Corgi Engine - Getting Started Tutorial

In this tutorial you'll learn the basic steps of the AIBrain graph for Corgi 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 AIBrain_Tutorial scene (and open it), that will serve as a starting point for this tutorial. Basically, it is the Corgi RetroAI scene with all enemies removed (with the exception of RetroSwordsman).

  1. Open the Enemies group to check the content: you will find the RetroSwordsman prefab and two other gameObjects (stripped out of all AI components): RetroSwordsmanGenerated and RetroSwordsmanPluggable.

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 RetroSwordman AIBrain (or anything you deem appropriate)

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

The RetroSwordsman AI Brain Structure

Select the RetroSwordsman 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: Patrol and Shooting

  • While in Patrol the swordsman will perform an AIActionPatrol action

  • While in Shooting the swordsman will perform an AIActionShoot action

  • The swordsman will exit the Patrol state if the target is within range (AIDecisionDetectTargetRadius)

  • The swordsman will exit the Shooting state after a while (AIDecisionTimeInState)

To create the AI Brain Graph we will need these nodes:

  • Two states

  • Two transistions

  • Two actions

  • Two decisions

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 Patrol and select Apply

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

  4. On the Patrol node, click the Set as starting state button: this will set the Patrol node as the entry state in the character brain

Each state should always have a unique name

Adding Transitions

Each state has a single transition, so we are going to create two and connect them with Patrol and Shooting:

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

  2. Click on the transitions output in Patrol state and drag it to the Input element of the transition node

  3. Repeat the first two steps for the Shooting state

Adding AI Decisions

The original swordsman has two decisions, each one connected with a state, so let's add them to the graph.

For the Patrol state:

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

  2. Set the Radius to 4

  3. Set the Target Layer to Player

  4. Connect the Output element to the Decision input of the patrol state AI Transition node

For the Shooting state:

  1. Right click on the graph canvas and select AI > Decision > Time In State

  2. Let the fields to their default values

  3. Connect the Output element to the Decision input of the shooting state AI Transition node

Adding AI Actions

The swordsman has two actions, each one connected with a state: let's add them to the graph.

For the Patrol state:

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

  2. Check the Avoid Falling value

  3. Set the Hole Detection Offset x value to 1

  4. Connect the Output element to the Actions input of the Patrol state node

For the Shooting state:

  1. Right click on the graph canvas and select AI > Action > Shoot

  2. Check the Aim At Target value

  3. Connect the Output element to the Actions input of the Shooting 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 ones:

  1. Connect the True State of the patrol AI Transition to the States in input of the Shooting state

  2. Connect the True State of the shooting AI Transition to the States in input of the Patrol state

Generating the Character AIBrain System

We are now ready to add the brain graph to a gameObject and generate all the Corgi 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 Corgi:

  1. Enable the RetroSwordsmanGenerated gameObject

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

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

  4. Click the Generate button and you will get the full working Corgi AI system for the RetroSwordsman (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 RetroSwordsmanPluggable gameObject

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

  3. Drag the RetroSwordsman AIBrain 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. Hit the Editor Play button and you should see the Corgi AI Brain structure generated

The AI Brain Pluggable is an extension of the regular Corgi AI Brain, so you'll have to keep it in your gameObject

Last updated