In this section, we will use the Unity physics engine to simplify the code a bit. In fact, in this example, we will attach a rigidbody component to our boids so that we can use rigidbody properties for the translation and steering behaviors of our boid. The rigidbody component is also useful to prevent our boids from overlapping with each other.
In this implementation, we have two components: the individual boid behavior and the controller behavior (the element that we referred to as the flock controller in the previous section). As before, the controller will be the object that the rest of the boids follow.
The code in the Flock.cs file is as follows:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class Flock : MonoBehaviour { internal FlockController controller;
private new Rigidbody rigidbody;
private...