Individual behavior

Boid is a term that was coined by Craig Reynold that refers to some bird-like object. We use this term to describe each individual object in our flock. Now, let's implement our boid behavior. You can find the behavior that controls each boid in our flock in the UnityFlock.cs script, which we'll examine now:

  1. The code in the UnityFlock.cs file is as follows:
using UnityEngine; using System.Collections; public class UnityFlock : MonoBehaviour { public float minSpeed = 20.0f; public float turnSpeed = 20.0f; public float randomFreq = 20.0f; public float randomForce = 20.0f; //alignment variables public float toOriginForce = 50.0f; public float toOriginRange = 100.0f; public float gravity = 2.0f; //seperation variables public ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.