In this series of articles I'm going to be implementing 'boids' in UnrealEngine. This is primarily a learning experience for myself as I expand my gameplay programming skills, and my C++! I am by no means an UnrealEngine or C++ expert so I may do dumb things occasionally, if you spot something, please drop me a message or comment to let me know :)
What Are 'Boids'?
Boids is the name of a series of algorithms created by Craig Reynolds in 1986 to simulate the behaviour of flocking or schooling animals. I based my particular implementation on pseudocode published by Conrad Parker. The basic structure of the main program loop is :
PROCEDURE move_all_boids_to_new_positions() Vector v1, v2, v3 Boid b FOR EACH BOID b v1 = rule1(b) v2 = rule2(b) v3 = rule3(b) b.velocity = b.velocity + v1 + v2 + v3 b.position = b.position + b.velocity END END PROCEDURE
The important parts here are the three rules that define the change in velocity of the boids, I'll go through them one by one. I will be referring to the collective group of boids as a 'flock' throughout these articles.
Rule 1 - Coherence
This rules states that each boid will try and move towards the centre of mass of the flock as a whole.
Rule 2 - Separation
This rule states that each boid will try to maintain a minimum distance from other boids.
Rule 3 - Alignment
This rule states that each boid will try to align it's direction with the rest of the flock.
Pretty simple huh? These three simple rules combine to create a surprisingly natural flocking behaviour in simulation. Now we will look at how to implement this in UnrealEngine....with a few differences that I will cover as we run through the code in the next section.
{fcomment}