Without further ado, let's dive into the Reynolds flocking algorithm. There are two main scripts for our flocking implementation: Boid.cs and FlockController.cs. The sample code for this chapter provides a scene with all the necessary setup for testing. You'll also notice a third script named TargetMovement.cs, which we use to move a target that our flock will follow around the scene.
For our boid, we can use a simple cube as a prefab. Of course, feel free to replace the cube with any art you want. Let's add the Boid.cs script to our boid prefab. The code looks like this:
using UnityEngine;
public class Boid : MonoBehaviour
{
[SerializeField]
private FlockController flockController;
//The modified direction for the boid.
private Vector3 targetDirection;
//The Boid's current direction.
private Vector3 direction...