Difference between revisions of "Behaviour"

From RPG Creation Kit
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
A Behaviour is a data structure that represents a bundle of AI instructions that are used to rule the AI actor that is utilizing it.
A Behaviour is a data structure that represents a bundle of AI instructions that are used to rule the AI actor that is utilizing it.


Behaviours are made of Behaviour Trees, which is an AI Model widely used in game development, essentially, they are just a collection of nodes that controls the flow of decision making of the AI. In this article it's not explained how a Behaviour Tree is created or how it works, if you're interested in knowing how in the inside Behaviour Trees works and how you can create your custom Behaviours. view [[Creating Behaviour Trees]].
Behaviours are made with Behaviour Trees, which is an AI Model widely used in games, essentially, they are just a collection of nodes that controls the flow of decision making of the AI. In this article it's not explained how a Behaviour Tree is created or how it works, if you're interested in knowing how in the inside Behaviour Trees works and how you can create your custom Behaviours. view [[Creating Behaviour Trees]].


Rather, here we will analyze what a Behaviour is and how it can be used to make the AI perform the actions you want.
Rather, here we will analyze what a Behaviour is and how it can be used to make the AI perform the actions you want.
Line 26: Line 26:


== Purpose State, the Memory of the AI ==
== Purpose State, the Memory of the AI ==
Imagine the AI is following the Player, in this case the AI has as "Current Target" the Player and as a Purpose Behaviour "Following".
Imagine the an AI actor is following the Player, in this case the AI has as "Current Target" the Player and as a Purpose Behaviour "Following".


Now Imagine a bandit comes out of nowhere attacking the Player, the follower will perceive the threat and switch tho the Combat Behaviour.  
Now Imagine a bandit comes out of nowhere attacking the Player, the follower will perceive the threat and switch to the Combat Behaviour.  


Upon switching the Combat Behaviour, he will also switch his target, as now from the Player, his target became the Bandit, and his purpose from following became killing.
Upon switching the Combat Behaviour, he will also switch his target, as now from the Player, his target became the Bandit, and his purpose from following became killing.


Everything works as expected, until the Bandit will die and the AI will switch back to its Purpose Behaviour. The "Current Target" of the follower is in fact still "Bandit", so the result will be that instead of following the player, the AI actor will follow the dead bandit.
Everything works as expected, until the Bandit will die and the AI will switch back to its Purpose Behaviour. The "Current Target" of the follower is in fact still "Bandit", so the result will be that instead of following the player the AI actor will follow the dead bandit.


Here is where the '''Purpose State''' takes his place.
Here is where the '''Purpose State''' takes his place.


The Purpose State allows you to set a goal for the AI that will be pursued until that goal has been completed or until you set otherwise.
The Purpose State allows you to set a goal for the AI that will be pursued until that goal has been completed or until you set otherwise. It will be something the AI will remember, no matter if he switches Behaviour Trees, if he gets unloaded, if the game gets reloaded from a savegame or any other scenarios.
 
It is generally used when the AI needs to have a target that is not set whitin the Editor.
 
In the example of the Demo, while playing The Red Shade questline at some point Vera will become your follower and follow you to the end of the earth, no matter what happens, if you save and load the savegame, she will still follow you. That is '''until''' you progress with the quest by speaking with Martin, her goal of following you gets completed, and a new Behaviour is set to her.
 
Most of the Behaviours however does not require you to set goals, as they use refereces set in Editor and most importantly '''even if the Behaviour changes''', the AI is able to get back to what he was doing without needing extra references.
 
An example of this are the farmers outside the city, their Behaviour is set to pick a random "farming point" and use it, so even if you switch Behaviour at a certain point, when you'll give them the Farming Behaviour again, they'll just pick a new point and resume farming.
 
== Setting Behaviours ==
Default Behaviours are set in the [[Rck AI Editor]] or inside the Inspector while inspecting AI actors.
 
You can set and switch Behaviours at anytime while the game runs via [[Scripting]] or [[Events And Consequences|Events]].

Latest revision as of 15:16, 13 February 2022

A Behaviour is a data structure that represents a bundle of AI instructions that are used to rule the AI actor that is utilizing it.

Behaviours are made with Behaviour Trees, which is an AI Model widely used in games, essentially, they are just a collection of nodes that controls the flow of decision making of the AI. In this article it's not explained how a Behaviour Tree is created or how it works, if you're interested in knowing how in the inside Behaviour Trees works and how you can create your custom Behaviours. view Creating Behaviour Trees.

Rather, here we will analyze what a Behaviour is and how it can be used to make the AI perform the actions you want.

Keep in mind that while you do not need to know what a Behaviour Tree is and how to create it (because you can simply select which Behaviour the AI must follow between the existing ones), creating new Behaviour Trees unlocks the full potential of the Rck AI.

You can view a Behaviour as a brain for the AI, each Behaviour has its purpose and allows the AI to perform a certain set of actions, like roaming around the world, sitting on an chair or leaning against a wall, following a path, or attacking an enemy.

You can switch the current Behaviour of the AI at anytime, and you can even concatenate behaviours to create a set of more complex actions that the AI will execute.

Purpose Behaviour and Combat Behaviour

Each AI actor has two Behaviours set at time.

  • A Purpose Behaviour: used for when the AI actor is not in combat, that rules the neutral behaviour of the actor.
  • A Combat Behaviour: used for when the AI engages in combat with an enemy target.


Every time an AI actor perceives a threat or is attacked, he enters in combat and the Current Behaviour is switched to the Combat Behaviour.

When the AI finishs his fight, he will switch back to his Purpose Behaviour.


So we can say that the Purpose Behaviour is the objective of the AI, the why he lives in the world, hence, the purpose, while the Combat Behaviour simply describes how the AI has to fight. There are diverse Purpose Behaviour, while (in the Demo) every AI uses the same Combat Behaviour.

Purpose State, the Memory of the AI

Imagine the an AI actor is following the Player, in this case the AI has as "Current Target" the Player and as a Purpose Behaviour "Following".

Now Imagine a bandit comes out of nowhere attacking the Player, the follower will perceive the threat and switch to the Combat Behaviour.

Upon switching the Combat Behaviour, he will also switch his target, as now from the Player, his target became the Bandit, and his purpose from following became killing.

Everything works as expected, until the Bandit will die and the AI will switch back to its Purpose Behaviour. The "Current Target" of the follower is in fact still "Bandit", so the result will be that instead of following the player the AI actor will follow the dead bandit.

Here is where the Purpose State takes his place.

The Purpose State allows you to set a goal for the AI that will be pursued until that goal has been completed or until you set otherwise. It will be something the AI will remember, no matter if he switches Behaviour Trees, if he gets unloaded, if the game gets reloaded from a savegame or any other scenarios.

It is generally used when the AI needs to have a target that is not set whitin the Editor.

In the example of the Demo, while playing The Red Shade questline at some point Vera will become your follower and follow you to the end of the earth, no matter what happens, if you save and load the savegame, she will still follow you. That is until you progress with the quest by speaking with Martin, her goal of following you gets completed, and a new Behaviour is set to her.

Most of the Behaviours however does not require you to set goals, as they use refereces set in Editor and most importantly even if the Behaviour changes, the AI is able to get back to what he was doing without needing extra references.

An example of this are the farmers outside the city, their Behaviour is set to pick a random "farming point" and use it, so even if you switch Behaviour at a certain point, when you'll give them the Farming Behaviour again, they'll just pick a new point and resume farming.

Setting Behaviours

Default Behaviours are set in the Rck AI Editor or inside the Inspector while inspecting AI actors.

You can set and switch Behaviours at anytime while the game runs via Scripting or Events.