- Home /
Am I using Behavior Designer correctly to control the AI of my character?
I download Behavior Designer and have been watching videos and reading the documentation. I ran into some confusion with many of the tutorials attaching the behavior script directly to the game object that represented their character.
There are 2 problems with this. I never need AI functions to directly modify my game object, the controller will handle making sure it's position is correct, animations are playing, etc.
If the game object is out of view and set to inactive, I don't want to disable the decision tree.
I want is to modify my ACTUAL character's state, which is a class. This is where AI and actions really take place, in the model, the rest is just visual.
This is what I came up with based on the documentation and just wanted to make sure it was the correct approach.
I save my behavior as an external behavior. When a character is instantiated, I have the controller create an additional game object called CharacterAI_Character#.
The action scripts need a way to access the specific character they should be working with. I have a list of characters in the world in my world controller. So I get the index of the character in this list and set it to a private variable integer of the behavior attached to the AI gameobject.
Now when I call an action I pass the integer to each action which calls the world controller again to get the character from the list. From here I call functions in the character class.
So now all my actions look like this:
public class TestAction : Action {
Character c;
public SharedInt characterNumber;
public override void OnStart()
{
c = WorldController.Inst.world.characters[characterNumber.Value];
}
public override TaskStatus OnUpdate()
{
if(c.DoStuff())
{
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
Your answer
Follow this Question
Related Questions
Animator/Behaviour I want to get all the transitions of a state 0 Answers
Conflicting animations (attack and idle) 1 Answer
Behavior Tree Barebones Tutorial 5 Answers
Avoidance Behaviour 2 Answers