Hawk Attack

Predator-prey dynamics in the murmuration — how a single hawk drives escape behavior, flock splitting, and wave-like avoidance cascades.

Why a Hawk?

Real starling murmurations aren't just aerobatic displays — they're partly an anti-predator defense. Peregrine falcons and sparrowhawks hunt at dusk, precisely when murmurations form. The dense, shifting cloud of thousands of birds makes it difficult for a raptor to isolate and track a single target. The dramatic shape-shifting, sudden splits, and cascading waves that make murmurations so visually stunning are at least partly driven by birds reacting to a predator's approach.

The hawk model in this simulation tests how escape behavior interacts with the base flocking rules. A single predator is enough to produce flock splitting, panic waves, and reformation dynamics that don't appear from the boids rules alone.

How the Hawk Works

The hawk is a single agent that operates outside the normal boids rules. It has its own steering logic, speed limits, and targeting strategy.

Target selection

Each frame, the hawk steers toward the densest bird in the flock — the bird with the highest smoothed neighbor count from the density-counting pass. This models a real raptor's strategy of aiming for the thickest part of the flock, where confusion is highest and a lucky strike is most likely.

Because the density counts are smoothed over time (fast drop, slow rise), the hawk's target doesn't flicker between random birds. It locks onto a dense region and pursues it, switching only when the density landscape shifts meaningfully.

Steering and speed

The hawk uses the same steer-toward formula as the boids: compute the desired velocity toward the target, subtract the current velocity, and clamp the resulting force to a maximum. The hawk's force cap (Agility) controls how tightly it can turn — lower agility means wider, sweeping passes; higher agility means the hawk can track a dodging flock more closely.

desired = normalize(target - hawkPos) * hawkSpeed
steer = clamp(desired - hawkVelocity, PRED_FORCE)

Hawk speed is set as a percentage of the flock's max speed. At 100% the hawk matches the birds; above 100% it can overtake them; below 100% the flock can outrun it. A minimum speed of 50% of hawk speed prevents the hawk from stalling.

Spawning and re-entry

When enabled, the hawk spawns on a sphere around the flock centroid (biased toward the upper hemisphere) and aims inward. If the hawk drifts more than 250 units from the flock center — missing a pass and sailing out into empty space — it teleports back to the entry sphere for another approach. This keeps the hawk perpetually engaged with the flock without scripted flight paths.

Escape Behavior

Birds don't just passively avoid the hawk through normal separation. When the hawk gets close, birds enter a distinct escape state with different physics.

The escape radius

A spherical zone around the hawk defines the escape trigger. Any bird inside this radius immediately enters full escape mode — its escape factor jumps to 1.0. Birds outside the radius gradually blend back to normal flocking over a configurable time (the blend-back parameter).

inside radius → escFade = 1.0 (full panic)
outside radius → escFade -= dt / blendTime (gradual recovery)

Escape steering

A bird in escape mode steers directly away from the hawk, using a boosted speed target and increased maximum force. The escape steering replaces the normal alignment and cohesion forces — a panicking bird stops trying to match its neighbors' heading or pull toward the group center. It just flees.

Crucially, boid-boid separation is also cancelled during escape. Panicking birds ignore each other entirely and flee directly away from the hawk. This models the real behavior of prey animals in a predator's strike zone: collision avoidance becomes secondary to survival. It also produces more dramatic flock-splitting because escaping birds don't push each other sideways — they all radiate outward from the hawk.

Blend-back

When a bird leaves the escape radius, it doesn't snap back to normal flocking. The escape factor decays linearly over the blend-back time (default 0.5 seconds of sim-time). During this transition, the bird's forces are interpolated between full escape and normal flocking:

force = normalForces + (escapeForces - normalForces) * escFade

Short blend times produce sharp transitions — birds snap back to formation quickly. Longer blend times create a lingering disarray as birds gradually rejoin the flock. The blend also affects the boosted escape speed, which tapers smoothly back to the normal max speed.

The Escape Radius Visualization

The escape radius is invisible by default, but the simulation provides two ways to see it:

Red wireframe sphere and red bird coloring

Toggling Show escape radius displays both a faint red wireframe sphere centered on the hawk (sized to the current escape radius) and colors birds currently inside the radius bright red, overriding any density or velocity coloring. This makes the trigger zone directly visible — the wireframe shows the boundary while the red birds show exactly who is panicking. A moving red stain on the flock surface follows the hawk's path, and birds outside the radius retain their normal color (gray, density, or velocity).

The Controls

The Hawk tab in the simulation's control bar groups all hawk-related parameters. Enable the hawk with the toggle, then adjust its behavior in real time.

Hawk toggle

Enables or disables the hawk predator. When turned on, the hawk spawns on a sphere around the flock and begins hunting. Turning it off removes the hawk and lets escape fades decay to zero.

Hawk speed (PRED_SPEED_PCT)

The hawk's top speed as a percentage of the flock's max speed. At 100% the hawk matches the birds; at 150% it can close gaps quickly. Very high values make the hawk devastating — it punches through the flock before birds can react. Lower values let the flock outmaneuver it.

Agility (PRED_FORCE)

The hawk's maximum steering force — how tightly it can turn. Low agility (1–2) makes the hawk fly wide, sweeping arcs that push the whole flock aside. High agility (5+) lets it track individual dense regions and cut through the flock repeatedly.

Escape radius (ESCAPE_RADIUS)

The distance from the hawk at which birds enter panic mode. A small radius (2–3) means only birds directly in the hawk's path react — the flock barely notices. A large radius (8+) triggers mass panic, splitting the flock dramatically as hundreds of birds flee at once.

Escape speed (ESCAPE_SPEED_PCT)

The target speed of escaping birds, as a percentage of max speed. Higher values mean birds flee faster, creating more dramatic speed differentials between panicking and calm birds. This is especially visible in velocity coloring mode, where escaping birds flash green (accelerating) and birds ahead of the wave flash red (braking as fleeing birds close in).

Escape accel multiplier (ESCAPE_ACCEL_MULT)

Multiplied against the flock's normal MAX_FORCE during escape. A multiplier of 2 means escaping birds can turn twice as sharply as normal, letting them dodge more aggressively. Higher values produce more explosive scatter patterns.

Blend-back (ESCAPE_BLEND)

How many seconds of sim-time it takes for a bird to transition from full escape back to normal flocking after leaving the escape radius. Short values (0.1–0.2s) create snappy recovery — the flock reforms quickly behind the hawk. Long values (1–2s) leave a trail of disorganized birds in the hawk's wake.

Show escape radius

Toggles the red wireframe sphere around the hawk. Useful for understanding the relationship between the escape radius setting and the actual area of effect. Try adjusting the escape radius slider while this is visible to see the sphere grow and shrink.

Hawk camera modes

Two special camera modes are available when the hawk is active:

Hawk's eye places a chase camera behind the hawk, giving a raptor's-eye view of the attack. You see the flock part and scatter ahead as the hawk dives in.

Split shows the normal orbit view on the left half of the screen and the hawk's eye view on the right. This lets you watch both the flock-scale dynamics and the hawk's perspective simultaneously. Turning the hawk off returns to the standard orbit camera.

What Emerges

The hawk doesn't just scatter birds — it creates structured, repeatable dynamics that mirror real murmuration behavior:

Flock splitting

As the hawk passes through the flock, birds in its path flee outward while birds beyond the escape radius continue flocking normally. This creates a temporary split — the flock divides around the hawk's trajectory like water around a boat's prow. With separation cancelled during escape, the split is clean: fleeing birds radiate directly away rather than being deflected sideways by each other.

Avoidance cascades

The panic doesn't stay local. Escaping birds, fleeing at boosted speed, slam into calm birds ahead of them. Those calm birds react through normal flocking forces — separation pushes them aside, and if speed braking is active, they slow down. The disturbance propagates outward from the hawk's path as a wave, reaching birds that never came close to the hawk. This is the same cascade mechanism described on the Density Waves page, but triggered by a predator rather than random fluctuations.

Reformation

After the hawk passes, the adaptive centroid pull draws scattered birds back toward the flock center. Alignment and cohesion take over, reweaving the disrupted region into the flock. The reformation speed depends on homing strength and blend-back time — fast blend-back means birds rejoin the flock quickly; strong homing pulls distant stragglers back sooner.

These dynamics — splitting, avoidance waves, reformation — are exactly what field researchers observe in real starling murmurations under hawk attack. The simulation produces them from purely local rules: each bird reacts only to the hawk's proximity and its immediate neighbors.

Experimenting

Here's a recipe for exploring hawk behavior:

Tip: The hawk targets the densest bird in the flock. Enable density coloring to see where the hawk is aiming — it steers toward the reddest (most crowded) region.
Open the Murmuration Experiment →

Further Reading

How It Works covers the base flocking rules — separation, alignment, cohesion, adaptive centroid pull — that govern bird behavior outside the escape radius.
Density Waves explains the speed-braking mechanism and compression waves. Hawk attacks create a particularly dramatic trigger for these waves — escaping birds slam into the calm flock ahead, seeding braking cascades that propagate outward.