Corgi Engine - Getting Started Tutorial
In this tutorial you'll learn the basic steps of the AIBrain graph for Corgi Engine.
Last updated
In this tutorial you'll learn the basic steps of the AIBrain graph for Corgi 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 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).
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.
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 RetroSwordman AIBrain (or anything you deem appropriate)
Double-click on the asset to open the Editor
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
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 Patrol and select Apply
Repeat the first two steps, creating another node called Shooting
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
Each state has a single transition, so we are going to create two and connect them with Patrol and Shooting:
Right click on the Graph canvas and select AI > Transition: this will add a transition node
Click on the transitions output in Patrol state and drag it to the Input element of the transition node
Repeat the first two steps for the Shooting state
The original swordsman has two decisions, each one connected with a state, so let's add them to the graph.
For the Patrol state:
Right click on the graph canvas and select AI > Decision > Detect Target Radius
Set the Radius to 4
Set the Target Layer to Player
Connect the Output element to the Decision input of the patrol state AI Transition node
For the Shooting state:
Right click on the graph canvas and select AI > Decision > Time In State
Let the fields to their default values
Connect the Output element to the Decision input of the shooting state AI Transition node
The swordsman has two actions, each one connected with a state: let's add them to the graph.
For the Patrol state:
Right click on the graph canvas and select AI > Action > Patrol
Check the Avoid Falling value
Set the Hole Detection Offset x value to 1
Connect the Output element to the Actions input of the Patrol state node
For the Shooting state:
Right click on the graph canvas and select AI > Action > Shoot
Check the Aim At Target value
Connect the Output element to the Actions input of the Shooting 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 ones:
Connect the True State of the patrol AI Transition to the States in input of the Shooting state
Connect the True State of the shooting AI Transition to the States in input of the Patrol state
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.
The AI Brain Generator component adds a static brain structure to your character, just like you are used to do in Corgi:
Enable the RetroSwordsmanGenerated gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Generator
Drag the RetroSwordsman AIBrain we created above in the AI Brain Graph field
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
The AI Brain Pluggable generates all Corgi AI system at runtime from a list of brain graphs:
Enable the RetroSwordsmanPluggable gameObject
Click the Add Component button and select The Bit Cave > AI > AI Brain Pluggable
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)
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