O'Reilly logo

Unity AI Game Programming - Second Edition by Thet Naing Swe, Clifford Peters, Aung Sithu Kyaw, Ray Barrera

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Flocking using Unity's samples

In this section, we'll create our own scene with flocks of objects and implement the flocking behavior in C#. There are two main components in this example: the individual boid behavior and a main controller to maintain and lead the crowd.

Our scene hierarchy is shown in the following screenshot:

Flocking using Unity's samples

The scene hierarchy

As you can see, we have several boid entities, UnityFlock, under a controller named UnityFlockController. The UnityFlock entities are individual boid objects and they'll reference to their parent UnityFlockController entity to use it as a leader. The UnityFlockController entity will update the next destination ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required