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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.