boldai.com

 
 
 
 

Multiple Brains per ComponentΒΆ

One of the many strengths of Brain Builder rises from its ability to combine many simple rulesets into bigger behaviors. Among the examples, the two brains Obstacle Avoidance and Random Walk can be used together to make a character that walks around to random locations while avoiding obstacles in the world. Lets look at these brains, first separately and then together.

Below is a simple world consisting of some boxes and a character:

../_images/scene-1.png

As you can see, the Character’s got a Brain component without any brain datas attached. As a result, he stands completely still when the game is played. Add the obstacle avoidance brain to the character (found in Boldai/Brains), set the turning speed to 5, distance to 3, and play the game.

You may notice that nothing happens. Switch instead to scene view and move a block in front of the four green lines originating from the character, and watch how the guy steers away from it:

../_images/scene-2.png

Stop the game and replace the obstacle avoidance brain with the Random Walking brain (also in the Boldai/Brains folder). Set walking speed to 0.1 and radius to 10 (turning speed should still be 5). Play the game and watch as the character moves around to random locations passing while passing through all obstacles in the world:

../_images/scene-3.png

Wouldn’t it be great if those two behaviors could be combined to both walk aimlessly and avoid obstacles in the process. Stop the game and change the size property under Brain Datas to 2, and drag the Obstacle Avoidance brain to the second element in the array:

../_images/inspector-1.png

Again, set distance to 3 and play the game:

../_images/scene-4.png

It works! The character doesn’t walk into the big boxes while he walks around randomly.

If you have used the Beginners Blocks (see Getting Started with Beginners Blocks), you have already used this feature. The ability to combine multiple behaviors from different self-contained brains into one bigger behavior is a powerful tool for both rapid prototyping (e.g. if you keep a library of common behaviors ready to use for your next project) and for creating many characters with small variations in their behaviour.