Devlog

How real sheep behave — turning a 2024 flocking study into a game

Real sheep behaviour

Most herding games move the flock like a single blob with a flee-from-the-dog rule bolted on. That was my first prototype too, and it felt wrong in a way I could not name until I read the research.

In 2024 Jadhav and colleagues published Collective responses of flocking sheep (Ovis aries) to a herding dog in Communications Biology (7:1543). They put ultra-wideband trackers on a border collie and 14 merino sheep, recorded position twice a second across dozens of herding runs, and fitted a model to what actually happened. It is, as far as I know, the best public dataset on how a real flock reacts to a real dog.

Flockfjord’s flock is built on that paper. Below is each finding I used, what it meant in code, and — just as important — where I knowingly departed from it.

1. Sheep track a few neighbours, not all of them

The classic Reynolds-style boid averages every neighbour inside a radius. The measured sheep do something different and much more interesting: each animal responds to a small, topological set of neighbours — roughly the nearest handful, regardless of how far away they happen to be — and the set is not fixed.

In Flockfjord each sheep perceives its 7 nearest flockmates, then picks 4 at random to be attracted toward and 2 of those to align with. The choice is re-rolled about every 0.35 seconds.

const val K_NEIGHBORS = 7
const val N_ATTRACT   = 4
const val N_ALIGN     = 2
const val NEIGHBOR_RESAMPLE = 0.35f

That randomness is not decoration. It is the mechanism that keeps a small flock cohesive without freezing it into a crystal: because every sheep keeps swapping which mates it cares about, the group stays connected while individual paths stay slightly ragged. Averaging all neighbours produces a flock that glides like a single rigid object. Sampling a few produces one that breathes.

Attraction beats alignment, on purpose

The paper measured flock elongation perpendicular to the direction of travel — the group is wider than it is long while being driven. That falls out naturally if attraction is weighted more strongly than alignment, so that is how it is tuned: attraction ≈ 1.5, alignment ≈ 0.9. Swap the weights and you get a long snake instead of a broad front, which is exactly what my first prototype did wrong.

2. Information flows front to back

In the recordings the flock does not turn as one instantaneous unit. The animals in front commit to a direction and the rest follow — the response propagates backwards through the group.

To get that, sheep cannot be identical. Each one in Flockfjord has a fixed reactivity value between 0.55 and 1.0. Bolder sheep feel the dog’s pressure sooner, so they move earlier, so they end up at the front — and stay there. A stable front-to-back order emerges without any code that assigns ranks.

Later I made reactivity derive from two traits the player can actually see: age and size. Young lambs are quick and flighty and push to the front; big old ewes are calm, heavy and lag behind. The hierarchy is now visible in the flock’s colours and silhouettes rather than hidden in a number.

3. The dog is barely faster than the sheep

This one changed the whole game. In the data the dog averaged about 1.5 m/s against the sheep’s 1.3 — roughly 15% faster. Real herding is not won by outrunning anything. It is won by being in the right place.

My prototype’s dog was more than twice the flock’s speed, and it made the game trivial: you could always sprint around and fix any mistake. Cutting the dog’s speed to 4.4–5.4 against a panicked sheep’s 3.4 (a compromise: still faster than the study, because a phone game cannot ask for a five-minute outrun) turned the game into one about anticipation. You cannot repair a bad position. You have to not take it.

4. Turning rate depends on where the dog is

The paper measured something a herder would recognise instantly: when the dog sits directly behind the flock, the flock’s turning rate is near zero. Move the dog off to one side and the group swings away.

In code, when the dog is behind the flock but laterally offset, every sheep receives the same perpendicular push:

// The whole flock is turned as one body, rather than each
// sheep fleeing individually — which shattered the group.
const val HERD_TURN = 5.0f

Applying the force uniformly is the trick. If each sheep merely flees the dog on its own, pressure from the side blows the flock apart. Applying one shared turning force keeps it intact, and makes flanking — running an arc around the group rather than charging it — the core skill of the game.

5. Prey can tell hunting from not hunting

This one comes from the wider literature rather than the 2024 paper — Mech’s wolf work, and Andersson’s 2015 heart-rate study of sheep worked by border collies. Prey animals read intent. Wolves can walk through caribou without provoking a reaction; sheep stop fleeing the moment a hunting wolf breaks off.

So in Flockfjord the dog’s speed, not just its distance, determines the pressure it applies:

val intent = (speed / style.maxSpeed).coerceIn(0f, 1f)

A dog that walks up applies gentle pressure. The same dog sprinting to the same spot panics the flock. It is the single mechanic that most changes how people play once they notice it: you learn to arrive slowly.

What I did not model

Being honest about the gaps matters more than the list of features:

  • Terrain. The study was on flat ground. Sheep in Flockfjord do not react to slope at all — a ridge is scenery and an obstacle, not something they avoid climbing.
  • Individual recognition. Real sheep know each other and have preferred companions. Mine pick neighbours at random from whoever is near.
  • Grazing behaviour proper. My grazing is a timer gated on calmness, not a model of feeding.
  • Flock size. Fourteen sheep on a field is not twenty on a mountain pass. The parameters are tuned for play, not fitted to data.

The goal was never simulation for its own sake. It was to find out whether a game built on how sheep actually behave would be more interesting than one built on how we assume they do. It is — and the reason is specific: real flock behaviour gives the player a system that pushes back coherently instead of a puzzle with a solution.

Sources

  • Jadhav, V., Pasqua, R., Zanon, C., Roy, M., Tredan, G., Bon, R., et al. (2024). Collective responses of flocking sheep (Ovis aries) to a herding dog. Communications Biology 7:1543.
  • Strömbom, D., et al. (2014). Solving the shepherding problem: heuristics for herding autonomous, interacting agents. J. R. Soc. Interface 11:20140719.
  • Andersson, A. (2015). Behaviour and heart rate in sheep when herded by Border collies. SLU studentarbete 643.
  • Mech, L. D. (1970). The Wolf: Ecology and Behavior of an Endangered Species.

Flockfjord is a sheep herding game for Android built on real sheepdog research — no engine, no 3D files, every mesh and sound generated in code.

Play the open beta About the game