I read and understand the basic of flocking algorithm. Basically, we need to have 3 behaviors:
1. Cohesion
2. Separation
3. Alignment
From my understanding, it's like a state machine. Every time we do an update (then draw), we check all the constraints on both three behaviors. And each behavior returns a Vector3
which is the "correct" orientation that an object should transform to. So my initial idea was
/// <summary>
/// Objects stick together
/// </summary>
/// <returns></returns>
private Vector3 Cohesion() {
Vector3 result = new Vector3(0.0f, 0.0f, 0.0f);
return result;
}
/// <summary>
/// Object align
/// </summary>
/// <returns></returns>
private Vector3 Align() {
Vector3 result = new Vector3(0.0f, 0.0f, 0.0f);
return result;
}
/// <summary>
/// Object separates from each others
/// </summary>
/// <returns></returns>
private Vector3 Separate() {
Vector3 result = new Vector3(0.0f, 0.0f, 0.0f);
return result;
}
Then I search online for pseudocode but many of them involve velocity and acceleration plus other stuffs. This part confused me. In my game, all objects move at constant speed, and they have one leader. So can anyone share me an idea how to start on implement this flocking algorithm? Also, did I understand it correctly? (I'm using XNA 4.0)