Collision detection is provided by Unity. Our collisions are in-elastic, meaning the objects which collide lose kinetic energy after the collision.
For a boid in the air, we assume no air resistance in contrast to a submerged boid, which experiences significant drag. The predator boids have a much larger volume, and larger cross sectional area, than the smaller prey boids. Because of this they experience more drag, giving the prey a slight advantage.
From Archemede's Principle, we know that the buoyant force exerted on an object submerged in water will be equal to the weight of the water displaced by the object. To simulate buoyancy, we would have to calculate and exert this force. However, nature offers us a shortcut: fish are naturally buoyant, using their swim bladder to maintain their level in the water. In essence, the weight of the water they displace is equal to their own weight, meaning to simulate buoyancy we need only disable gravity.
Note: This clip uses the original rule-based behaviour for boids directly from Sebastian Lague's code, and not our RL-agent driven behaviour.
Drafting is a technique employed by fish in nature to conserve energy and move more quickly. If one fish is swimming in the slipstream of another fish, the effects of drag are reduced. This enables the fish to swim more efficiently, allowing the fish to swim faster to avoid predators or conserve energy when moving in a school.
We implemented a drafting system into our project to reduce drag when a boid is swimming in a slipstream. In order to simulate this effect, each boid in our system has a trail of permeable blocks behind it. Each of the permeable blocks follows the path of the block before it to create curving slipstreams that follow the path of the boid more accurately. When a boid triggers a slipstream, it calculates the angle between it's forward vector and the forward vector of the block. If the absolute value of the angle is less than 90 degrees, the boid's drag is reduced by the cosine of the angle between the boid and the slipstream.