Simulating a starling murmuration

Starlings

A recurrent question about UnitySteer is how to implement behavior like that of a flock of starlings (seems that Mr. Reynolds was right on the money when he chose flocking for his paper).

Usually the person who writes mentions that their implementation is “getting there”, but they’re not quite happy with the result yet. The main issue with the question is that if the results are right or not are all about perception - it’s not a problem where there is a single, provably optimal solution.

With that in mind, I’ll detail some of the aspects of the starlings from the video above, and mention how you can mimic them in UnitySteer.

The behavior

The main characteristics of the flock seem to be:

  • Fast direction and speed change.
  • A flock can easily break into sub-flocks.
  • They revolve around a focal point (maybe the area where their nests are, or where they usually rest).
  • Controlled or limited vertical movement.

UnitySteer settings

First, make sure you have gone through the UnitySteerExamples repository, in particular the Neighbor Examples. You’ll need to understand the behaviors, their properties, and how the steerings interact. Once you have done that, you can start building things based on the behaviors for boids.

Direction and speed change

MaxSpeed is only a small factor on this - it controls the maximum speed that a vehicle can move at, but doesn’t control how quickly a vehicle can change direction. Having said that, you will likely want to have a minor variation on agent maximum speeds, to make it look more organic.

You can control how suddenly a vehicle can change its direction using properties TurnTime and MinSpeedForTurning. Bear in mind that the lower the TurnTime, the more jittery a vehicle can become.

The maximum amount of force you can apply, set by changing MaxForce, might help.

Speed change in a vehicle is controlled by properties AccelerationRate and DecelerationRate. I can’t tell if these two are equal for the starlings, so you’ll need to tweak and see how they fit your example.

Subflocks

Small subflocks tend to break away from the main group. In boid terms, starlings seem to have a narrow definition of what constitutes a neighbor, as defined by their own forward vector.

This might be implemented by lowering SteerForNeighborGroup‘s AngleCos/AngleDegrees to be narrower than the default of about 45 degrees. This would cause starlings to only consider as neighbors those that are more directly aligned with the direction they are going. The net effect is that if some are going in a slightly different direction, a subgroup will break away.

You may also need to play with the MinRadius property, which controls the distance at which a vehicle is definitely considered a neighbor, regardless of alignment. If the MinRadius is too large, it will potentially override the angle alignment properties.

When a subflock breaks away, it’s not clear how big the range that their members come from. This would be controlled with how far away a vehicle looks for neighbors, using Radar‘s DetectionRadius value.

Revolving around a focal point.

This behavior is the easiest one: simply use SteerForTether to ensure agents aim to stay around a particular point (which may not be the same for all of them, if you want to simulate multiple nests). You will want to give them a wide range for the tether, as otherwise vehicles will just tend to hover around it.

Controlled or limited vertical movement

Finally, the starlings tend to do very little vertical movement. They go up and down a bit, but then stabilize towards flying horizontally again at their new height.

This is something that UnitySteer does not provide by default - vehicles can either movie on an axis (as defined by AllowedMovementAxes) or not. The best way to simulate that would be creating a new steering behavior that gradually lerps the up vector so that it’s stabilized the vehicle after a certain period of time of climbing/diving.

Alternatively, you may want to limit the vertical angle at which they can fly, since you’ll rarely (or never) see a starling flying straight up or down.

Wrapping up

I hope this has given you a clearer view of how the various UnitySteer properties interact. If you still have some questions, reach out and let me know!


Published: 2015-07-06