November 22nd, 2026

How to add flocks of birds and schools of fish to a 2D game with boids

A flock of swallows and a school of fish that move on their own, from three rules and a goal that swings like a pendulum. Every number, tested Godot 4.6 code and a project to download.

Paste it into Claude Code, Codex, Cursor or any coding agent.

# Add flocking birds and schools of fish to my game

My 2D game's sky and water feel empty. Add a flock of small birds and a school of fish with boids: three rules between neighbors, plus a goal that swings back and forth to keep each group in the scene. Fish should flee a threat (a bird dipping to the water, the player, the cursor).

Before you write code, look at my project: engine, tick rate, art resolution, the visible area, sprite drawing and layering, and what sits in front of the sky or water. Fit this into what is there and keep my art and numbers. Ask me where the flock and school should go, and before adding art.

## How it works

- Each tick every agent adds three steering forces from the others within its neighbor radius: separation (away from anyone inside its personal space, weighted 1/distance), alignment (toward their average heading), cohesion (toward their middle). Compute all forces first, then move everyone.
- Each force is Reynolds steering: desired velocity minus current velocity, capped at the max acceleration. The sum is capped at twice that.
- A goal keeps them in the scene, not walls at the screen edges. Each agent follows its own copy of the goal a bit behind, takes on its velocity, and is pulled back once more than `slack` px away.
- The goal swings like a pendulum, x = cx + A cos(w t): slow at each end, fastest in the middle, ends C px higher. It may run past the screen edges.
- Each agent gets its own top speed and personal space, or they fly in rows.

## Numbers that matter

Art pixels, y down, 60 Hz (dt = 1/60), for 10 px birds and 11 px fish in a 384 x 216 view. For bigger sprites scale radii, speeds and accelerations together.

- Birds: 24. Neighbor radius 30, personal space 12. Weights separation 1.5, alignment 0.9, cohesion 0.4, goal 2.4, walls 2.6. Speed 25 to 200 px/s, steering cap 500 px/s^2, slack 22 px.
- Fish: 20. Neighbor radius 34, personal space 12. Weights 1.8, 2.5, 0.7, goal 1.3, walls 3.0, flee 3.5. Speed 25 to 56 px/s, steering cap 200 px/s^2, slack 16 px.
- Per agent (r a fresh uniform random each time): top speed = max * (0.8 + 0.4 r), personal space * (0.7 + 0.6 r), lag = min(r^1.6, 0.8) * L seconds, L 1.34 for birds, 1.5 for fish.
- Bird swing: A 160 px, period 6 s, B 28 (way back runs above), C 20 (ends higher). Fish: A 95, period 12 s, B 9, C 0. Center each swing in its open space: in my 480 x 268 scene (seen through x 20 to 404, y 30 to 246, water surface at y 173) birds use cx 255, cy 106 and fish cx 285, cy 206.
- Goal wobble, per agent and per axis: wander * sin(2 pi k t / 12 + phase), k a whole number 2 to 4, random phase, scene time t. 4 px for birds, 1.5 for fish. Not part of the goal velocity.
- Soft walls sit on the edge of the allowed space (birds: a floor at y 165, 8 px over the water; fish: the water box x 172 to 398, y 184 to 230). The push starts margin px inside the wall, is 1x at the wall and grows to 3x: walls_weight * steering_cap * clamp((x - (wall - margin)) / margin, 0, 3). Margin 6 for birds, 9 for fish.
- Flee: fish within 40 px of the threat on an oval (sqrt(dx^2 + (0.75 dy)^2)) steer toward unit(away) + (0, 0.6) at 1.5x max speed; top speed 1.4x while scared.
- Facing: flip once x speed is 6 px/s the other way, then hold at least 12 ticks. Pitch looks -15, 0, 15 degrees, change 4 degrees past halfway.
- Warm up 18 s before showing it.

## Pseudo code

```
goal(i, t):
    w = 2 pi / period
    u = w * fposmod(t - lag[i], period)
    gx = cx + A cos(u) + wander sin(...)          gy = cy + B sin(u) - C cos(u)^2 + wander sin(...)
    gvx = -A sin(u) w                             gvy = (B cos(u) + 2 C cos(u) sin(u)) w

steer(i, dir, speed):                             # Reynolds steering
    return cap(unit(dir) * speed - v[i], acc)

step(t, dt):
    for each agent i:
        cnt = 0; heading = 0; middle = 0; away = 0; close = false; scared[i] = false
        for each other agent j:
            d = p[i] - p[j]; d2 = dot(d, d)
            if d2 < radius^2: cnt += 1; heading += v[j]; middle += p[j]
            if d2 < (sep_radius * space[i])^2: close = true; away += d / d2
        f = 0
        if close: f += w_sep * steer(i, away, vmax)
        if cnt > 0:
            f += w_ali * steer(i, heading, vmax)
            f += w_coh * steer(i, middle / cnt - p[i], vmax)
        g, gv = goal(i, t)
        to = g - p[i]; dist = length(to)
        want = cap(gv + to * max(dist - slack, 0) * 1.5 / dist, vmax)
        f += w_goal * cap(want - v[i], acc)
        f += soft_walls(p[i])
        if threat and oval_distance(p[i], threat) < 40:
            scared[i] = true
            f += w_flee * steer(i, unit(p[i] - threat) + (0, 0.6), vmax * 1.5)
        force[i] = cap(f, 2 * acc)
    for each agent i:                              # move after all forces are known
        v[i] += force[i] * dt
        v[i] = unit(v[i]) * clamp(length(v[i]), vmin, top[i] * (1.4 if scared[i] else 1))
        p[i] += v[i] * dt
```

Godot: `_physics_process` with physics ticks at 60. Unity: `FixedUpdate` with `Time.fixedDeltaTime = 1/60`. Any engine: plain arrays and a loop, no physics engine. With hundreds of agents, bucket them in a grid with cells the size of the neighbor radius.

## Pitfalls

- Walls at the screen edges make the flock bunch up along them.
- An even-speed goal makes the flock reverse hard at each end. A high minimum speed stops it slowing into turns.
- Too much cohesion makes a ball.
- Flipping with no hold flickers mid-turn. Predicting the flip from the steering force flips some birds too early.
- To fly behind trees, draw them again over the birds.

## Check that it works

- A debug view for one agent: neighbor circle, neighbor dots, rule forces as arrows.
- Over 12 s two birds stay a few px apart (closest 4.3 px in my run, 1 to 3 px on other seeds); with the three rule weights at 0 they pile up within 0.1 px. That is the off switch: plain path following.
- Averaged over all birds and ticks they fly about 108 px/s. The flock's mean speed is about 53 at a turn (where the flock's mean x speed changes sign) and about 151 at its fastest. No bird drops under 25.
- 4 turns per 12 s; each bird's sprite flips 4 times, usually 1 tick after its x speed changes sign, and is never drawn facing backward above 20 px/s.
- A threat moving from x 420 to 200 along y 176 in 1.5 s, starting 5 s into the run (school middle near 307, 206), scares 17 of 20 fish at once. Compare against the same run without it: 1.4 s after it starts the school's middle is about 15 px deeper, and 5 s after it's within about 7 px again.

## Art it needs

Side-view sprites facing right: a bird about 10 px long, a fish about 11 px, each in three pitches (-15, 0, 15 degrees, by shifting columns whole pixels) and a 4-frame flap or tail swish. Use what the project has first.

If the SpriteCook MCP tools are available in this session, they can make the scene and sprites. Pixel Engine Image is 16 px at the smallest and fills its canvas, so draw 10 to 11 px sprites in code in the generated art's colors. Keep the sky and water open where the groups will go.

Source: SpriteCook (2D game assets made by your coding agent, for Claude, ChatGPT and Cursor)
Full guide with pictures, video and tested Godot code: https://www.spritecook.ai/blog/boids-flocking-birds-fish-2d-game

A big sky with nothing in it makes a scene feel empty. Animating a flock by hand is a lot of frames, and birds on a path just follow each other in a line. Boids fix that. Each bird only looks at the birds near it and follows three rules, and the flock comes out of that. Add a goal that keeps them in the scene, and the same code with other numbers runs a school of fish.

24 swallows and 20 fish, nothing keyframed. The scene is made with SpriteCook; the swallows and fish are drawn in code.

The three rules

Every tick, each bird finds its neighbors: every other bird within 30 px. Then it adds up three steering forces.

  • Separation (red): away from any bird closer than 12 px, harder the closer it is.
  • Alignment (blue): toward the neighbors' average heading.
  • Cohesion (green): toward the neighbors' middle.
Close up of the flock over the sunset sky. One swallow has a large dashed white circle around it, its 30 px neighbor radius, and a small dashed red circle, its personal space. White dots sit over its five neighbors. A red arrow points away from the bird next to it, a blue arrow points along the flock's heading and a green arrow points toward the middle of its neighbors

Each force is a steering force (Craig Reynolds' word for it): the velocity the bird wants, minus the one it has, capped at 500 px/s². The cap is why they turn in arcs instead of snapping around. The swallows weigh the three rules 1.5, 0.9 and 0.4.

Give every bird a bit of its own, or they fly in neat rows: a top speed from 0.8 to 1.2 times 200 px/s and a personal space from 0.7 to 1.3 times 12 px.

With the rules on, the closest two birds get in 12 s is 4.3 px. Turn all three off and they pile up on the goal, 0.06 px apart.

A goal instead of walls

Rules alone don't keep a flock in your scene. It drifts off. My first try put soft walls at the frame edges, and the flock bunched up along them like it hit glass.

What works better is a goal: a point the flock follows. Each bird gets its own spot on the goal's path, up to 1.07 s behind it (most are near the front, a few straggle). It takes on the goal's velocity, and if it's more than 22 px from its spot, it also gets pulled back. Inside those 22 px the three rules decide where it goes.

The path is allowed to run past the frame edges, so the flock leaves the screen for a moment and comes back. The only wall is a floor over the water. Within 6 px of it, a bird gets pushed up.

Make the turns swing

My first goal went around a loop at an even speed. Each bird flew flat out, then reversed in a fraction of a second at each end, like it bounced off something.

A pendulum fixes that. The goal's x is cx + A cos(2π t / T), so it slows to a stop at each end and is fastest in the middle. The two ends sit 20 px higher than the middle, so the flock climbs into each turn, hangs for a moment, and swoops back down. The way back runs 28 px above the way out.

var _gx := 0.0
var _gy := 0.0
var _gvx := 0.0
var _gvy := 0.0


func _goal(i: int, t: float) -> void:
    # The goal swings like a pendulum: x = cx + A cos. It eases to a stop at both ends,
    # the ends sit C px higher (the flock climbs into each turn), and the way back
    # runs B px above the way out.
    var w: float = TAU / cfg.period
    var u := w * fposmod(t - lag[i], cfg.period)     # wrapped: sin and cos get small angles
    var c := cos(u)
    var s := sin(u)
    var wob := TAU * wob_k[i] * fposmod(t, 12.0) / 12.0
    _gx = cfg.cx + cfg.a * c + cfg.wander * sin(wob + wob_px[i])
    _gy = cfg.cy + cfg.b * s - cfg.c * c * c + cfg.wander * sin(wob + wob_py[i])
    _gvx = -cfg.a * s * w
    _gvy = (cfg.b * c + 2.0 * cfg.c * c * s) * w
The whole lake scene with the flock in the middle of the sky heading left. A dotted white loop runs through the sky from behind the pine on the left to past the right edge: one dot every eighth of a second. The dots bunch up at both ends of the loop and spread far apart in the middle

One dot every eighth of a second. They bunch up at the ends, where the flock is slow, and spread out in the middle, where it's fast.

For the swallows the swing is 160 px to each side of the middle and takes 6 s there and back. They average 108 px/s, slow to 53 px/s at a turn and reach 151 px/s in the middle. The minimum speed of 25 px/s is what lets them slow down at all.

Two line charts of x speed over 12 seconds for three birds. Top, an even-speed lap: the lines sit flat near plus and minus 130 px/s and flip between them. Bottom, the swing: smooth waves that peak near 150 px/s and pass slowly through zero

Same code for the fish

The school runs the exact same code. Only the numbers change:

SwallowsFish
Count2420
Neighbor radius30 px34 px
Too close12 px12 px
Separation, alignment, cohesion1.5, 0.9, 0.41.8, 2.5, 0.7
Speed, min to max25 to 200 px/s25 to 56 px/s
Steering cap500 px/s²200 px/s²
Pull to the goal2.4, 22 px slack1.3, 16 px slack
Swing160 px, 6 s95 px, 12 s
Wallsa floor over the waterthe open water, 9 px soft

The fish align almost three times harder than the swallows, so the school turns as one body. The swallows hold together loosely and string out.

Scare the fish

A threat is any point the fish should get away from: a bird that dips to the water, the player, the cursor. Every fish within 40 px of it (an oval, 0.75 as tall as it's wide) steers straight away at 1.5 times its top speed, with a pull downward, and may swim 1.4 times faster while it's scared.

Close up of the water as three swallows skim the surface. Below them the school of fish has spread out downward, swimming away from the spot where the birds touched the water

In the test a swallow skims across the lake in 1.5 s. It scares 17 of the 20 fish, the school is 15 px deeper 1.4 s later than in the same run without it, and 5 s after the skim starts it's back within 7 px of its path.

Small sprites: facing and pitch

A 10 px bird only has a few looks: facing left or right, and nose up, level or down (-15, 0 and 15 degrees). Pick them with a little hold, or they flicker.

  • Facing flips once the x speed is 6 px/s the other way, and then stays for at least 12 ticks.
  • Pitch changes once the heading is 4 degrees past halfway to the next look.

Each bird flips 4.0 times in 12 s, once per turn. The flip comes 1 tick after its x speed changes sign (the median, 5 at most). That's at the top of the swing, where the bird barely moves, so no bird is ever drawn facing backward while it's going faster than 20 px/s. I also tried flipping a few ticks early by predicting the turn from the steering force. It turned some birds too soon, so I took it out.

To fly behind the pine, draw the birds, then draw the pine's pixels (and the grass in front) over them again.

The code

Four Godot 4 scripts and no art files. Get them in one zip: boids-flocking-godot.zip (9 KB). Open the folder in Godot and press play: hold the mouse in the water to scare the fish, space to see one bird's neighbors and steering.

  • flock.gd is the flock: the three rules, the goal, walls and the threat, plus a per-tick step().
  • facing.gd picks each sprite's facing and pitch.
  • lake.gd has the numbers for the swallows and the fish.
  • play.gd is the scene you can play, with gray-box sprites.
  • test.gd is the headless test.

The three rules, inside step():

for j in n:
    if j == i:
        continue
    var dx := px[i] - px[j]
    var dy := py[i] - py[j]
    var d2 := dx * dx + dy * dy
    if d2 < r2:                       # a neighbor: count its heading and position
        cnt += 1
        avx += vx[j]
        avy += vy[j]
        cx += px[j]
        cy += py[j]
    if d2 < rs * rs:                  # too close: away from it, harder the closer it is
        close = true
        sx += dx / d2
        sy += dy / d2
var fx := 0.0
var fy := 0.0
if close:                             # separation
    _steer(i, sx, sy, cfg.vmax, acc)
    fx += cfg.w_sep * _ox
    fy += cfg.w_sep * _oy
if cnt > 0:
    _steer(i, avx, avy, cfg.vmax, acc)   # alignment: toward the neighbors' average heading
    fx += cfg.w_ali * _ox
    fy += cfg.w_ali * _oy
    # cohesion: toward their middle
    _steer(i, cx / cnt - px[i], cy / cnt - py[i], cfg.vmax, acc)
    fx += cfg.w_coh * _ox
    fy += cfg.w_coh * _oy

The pull toward the goal:

# the goal: its own speed, plus a pull back once the agent is more than `slack` px away
_goal(i, t)
var gx := _gx - px[i]
var gy := _gy - py[i]
var gd := sqrt(gx * gx + gy * gy)
var pull := maxf(gd - cfg.slack, 0.0) * 1.5 / maxf(gd, 1e-9)
var wx := _gvx + gx * pull
var wy := _gvy + gy * pull
var wl := sqrt(wx * wx + wy * wy)
if wl > cfg.vmax:
    wx *= cfg.vmax / wl
    wy *= cfg.vmax / wl
_cap(wx - vx[i], wy - vy[i], acc)
fx += cfg.w_goal * _ox
fy += cfg.w_goal * _oy

And the steering every rule goes through:

func _steer(i: int, dx: float, dy: float, speed: float, acc: float) -> void:
    # Reynolds steering: the velocity you want (that way, at `speed`)
    # minus the one you have, capped
    var l := sqrt(dx * dx + dy * dy)
    _cap(dx / maxf(l, 1e-9) * speed - vx[i], dy / maxf(l, 1e-9) * speed - vy[i], acc)


func _cap(x: float, y: float, m: float) -> void:
    var l := sqrt(x * x + y * y)
    var k := m / l if l > m else 1.0
    _ox = x * k
    _oy = y * k

Tested in Godot 4.6, 18 s of warm-up and then 12 s with a swallow skimming over the school, all numbers taken from Godot's own run:

  • With the rules on, two birds never get closer than 4.3 px. With all three off, they come within 0.06 px.
  • The swallows average 108 px/s, 53 px/s at a turn and 151 px/s at the fastest, and none ever drops under 25 px/s.
  • Each bird flips 4.0 times, 1 tick after its x speed changes sign (median), and none is ever drawn facing backward above 20 px/s.
  • The skim scares 17 fish and the school is 15 px deeper than without it, back within 7 px 5 s after.
  • A Python copy of the same code, which drew the pictures on this page, matches Godot bit for bit for the first 2.93 s. After that it slowly drifts apart, because Godot's sin and cos differ from Python's in the last bit and a flock grows tiny differences. Its speeds, flips and gaps come out the same.

Other engines

  • Unity. The same arrays in a MonoBehaviour, stepped in FixedUpdate at 60 Hz. Vector2 is fine there; I only used plain doubles to compare against Python.
  • Lots of birds. Every bird checks every other bird, so 24 birds is 552 checks a tick. For hundreds, sort them into a grid with cells the size of the neighbor radius and only check the cells around each bird.
  • Scale with your art. All lengths are in art pixels for 10 px swallows. For bigger sprites, scale the radii, speeds and steering caps by the same factor.

Common pitfalls

Walls at the frame edges. The flock bunches up along them. Use a goal and let the path run a little past the edges.

A goal that moves at an even speed. The flock goes flat out and then reverses in a fraction of a second at each end, and it looks like it bounced off a wall. Make it swing.

A minimum speed that's too high. Then the birds can't slow into a turn, and they make wide fast arcs. The swallows go down to 25 px/s.

Every bird the same. Same speed and same personal space give you rows. Give each one its own top speed, personal space and spot behind the goal.

Too much cohesion. The flock pulls into a tight ball. For birds keep it well under separation and alignment.

Flipping with no hold. In the middle of a turn the x speed hovers around zero and the sprite flickers between left and right. Wait for a few px/s the other way and keep the new facing for a few ticks.

Where to next

Add this to your game with your coding agent

The prompt has the numbers, pseudo code, pitfalls and checks from this guide, written so your agent can fit it into your own project.

# Add flocking birds and schools of fish to my game

My 2D game's sky and water feel empty. Add a flock of small birds and a school of fish with boids: three rules between neighbors, plus a goal that swings back and forth to keep each group in the scene. Fish should flee a threat (a bird dipping to the water, the player, the cursor).

Before you write code, look at my project: engine, tick rate, art resolution, the visible area, sprite drawing and layering, and what sits in front of the sky or water. Fit this into what is there and keep my art and numbers. Ask me where the flock and school should go, and before adding art.

## How it works

- Each tick every agent adds three steering forces from the others within its neighbor radius: separation (away from anyone inside its personal space, weighted 1/distance), alignment (toward their average heading), cohesion (toward their middle). Compute all forces first, then move everyone.
- Each force is Reynolds steering: desired velocity minus current velocity, capped at the max acceleration. The sum is capped at twice that.
- A goal keeps them in the scene, not walls at the screen edges. Each agent follows its own copy of the goal a bit behind, takes on its velocity, and is pulled back once more than `slack` px away.
- The goal swings like a pendulum, x = cx + A cos(w t): slow at each end, fastest in the middle, ends C px higher. It may run past the screen edges.
- Each agent gets its own top speed and personal space, or they fly in rows.

## Numbers that matter

Art pixels, y down, 60 Hz (dt = 1/60), for 10 px birds and 11 px fish in a 384 x 216 view. For bigger sprites scale radii, speeds and accelerations together.

- Birds: 24. Neighbor radius 30, personal space 12. Weights separation 1.5, alignment 0.9, cohesion 0.4, goal 2.4, walls 2.6. Speed 25 to 200 px/s, steering cap 500 px/s^2, slack 22 px.
- Fish: 20. Neighbor radius 34, personal space 12. Weights 1.8, 2.5, 0.7, goal 1.3, walls 3.0, flee 3.5. Speed 25 to 56 px/s, steering cap 200 px/s^2, slack 16 px.
- Per agent (r a fresh uniform random each time): top speed = max * (0.8 + 0.4 r), personal space * (0.7 + 0.6 r), lag = min(r^1.6, 0.8) * L seconds, L 1.34 for birds, 1.5 for fish.
- Bird swing: A 160 px, period 6 s, B 28 (way back runs above), C 20 (ends higher). Fish: A 95, period 12 s, B 9, C 0. Center each swing in its open space: in my 480 x 268 scene (seen through x 20 to 404, y 30 to 246, water surface at y 173) birds use cx 255, cy 106 and fish cx 285, cy 206.
- Goal wobble, per agent and per axis: wander * sin(2 pi k t / 12 + phase), k a whole number 2 to 4, random phase, scene time t. 4 px for birds, 1.5 for fish. Not part of the goal velocity.
- Soft walls sit on the edge of the allowed space (birds: a floor at y 165, 8 px over the water; fish: the water box x 172 to 398, y 184 to 230). The push starts margin px inside the wall, is 1x at the wall and grows to 3x: walls_weight * steering_cap * clamp((x - (wall - margin)) / margin, 0, 3). Margin 6 for birds, 9 for fish.
- Flee: fish within 40 px of the threat on an oval (sqrt(dx^2 + (0.75 dy)^2)) steer toward unit(away) + (0, 0.6) at 1.5x max speed; top speed 1.4x while scared.
- Facing: flip once x speed is 6 px/s the other way, then hold at least 12 ticks. Pitch looks -15, 0, 15 degrees, change 4 degrees past halfway.
- Warm up 18 s before showing it.

## Pseudo code

```
goal(i, t):
    w = 2 pi / period
    u = w * fposmod(t - lag[i], period)
    gx = cx + A cos(u) + wander sin(...)          gy = cy + B sin(u) - C cos(u)^2 + wander sin(...)
    gvx = -A sin(u) w                             gvy = (B cos(u) + 2 C cos(u) sin(u)) w

steer(i, dir, speed):                             # Reynolds steering
    return cap(unit(dir) * speed - v[i], acc)

step(t, dt):
    for each agent i:
        cnt = 0; heading = 0; middle = 0; away = 0; close = false; scared[i] = false
        for each other agent j:
            d = p[i] - p[j]; d2 = dot(d, d)
            if d2 < radius^2: cnt += 1; heading += v[j]; middle += p[j]
            if d2 < (sep_radius * space[i])^2: close = true; away += d / d2
        f = 0
        if close: f += w_sep * steer(i, away, vmax)
        if cnt > 0:
            f += w_ali * steer(i, heading, vmax)
            f += w_coh * steer(i, middle / cnt - p[i], vmax)
        g, gv = goal(i, t)
        to = g - p[i]; dist = length(to)
        want = cap(gv + to * max(dist - slack, 0) * 1.5 / dist, vmax)
        f += w_goal * cap(want - v[i], acc)
        f += soft_walls(p[i])
        if threat and oval_distance(p[i], threat) < 40:
            scared[i] = true
            f += w_flee * steer(i, unit(p[i] - threat) + (0, 0.6), vmax * 1.5)
        force[i] = cap(f, 2 * acc)
    for each agent i:                              # move after all forces are known
        v[i] += force[i] * dt
        v[i] = unit(v[i]) * clamp(length(v[i]), vmin, top[i] * (1.4 if scared[i] else 1))
        p[i] += v[i] * dt
```

Godot: `_physics_process` with physics ticks at 60. Unity: `FixedUpdate` with `Time.fixedDeltaTime = 1/60`. Any engine: plain arrays and a loop, no physics engine. With hundreds of agents, bucket them in a grid with cells the size of the neighbor radius.

## Pitfalls

- Walls at the screen edges make the flock bunch up along them.
- An even-speed goal makes the flock reverse hard at each end. A high minimum speed stops it slowing into turns.
- Too much cohesion makes a ball.
- Flipping with no hold flickers mid-turn. Predicting the flip from the steering force flips some birds too early.
- To fly behind trees, draw them again over the birds.

## Check that it works

- A debug view for one agent: neighbor circle, neighbor dots, rule forces as arrows.
- Over 12 s two birds stay a few px apart (closest 4.3 px in my run, 1 to 3 px on other seeds); with the three rule weights at 0 they pile up within 0.1 px. That is the off switch: plain path following.
- Averaged over all birds and ticks they fly about 108 px/s. The flock's mean speed is about 53 at a turn (where the flock's mean x speed changes sign) and about 151 at its fastest. No bird drops under 25.
- 4 turns per 12 s; each bird's sprite flips 4 times, usually 1 tick after its x speed changes sign, and is never drawn facing backward above 20 px/s.
- A threat moving from x 420 to 200 along y 176 in 1.5 s, starting 5 s into the run (school middle near 307, 206), scares 17 of 20 fish at once. Compare against the same run without it: 1.4 s after it starts the school's middle is about 15 px deeper, and 5 s after it's within about 7 px again.

## Art it needs

Side-view sprites facing right: a bird about 10 px long, a fish about 11 px, each in three pitches (-15, 0, 15 degrees, by shifting columns whole pixels) and a 4-frame flap or tail swish. Use what the project has first.

If the SpriteCook MCP tools are available in this session, they can make the scene and sprites. Pixel Engine Image is 16 px at the smallest and fills its canvas, so draw 10 to 11 px sprites in code in the generated art's colors. Keep the sky and water open where the groups will go.

Source: SpriteCook (2D game assets made by your coding agent, for Claude, ChatGPT and Cursor)
Full guide with pictures, video and tested Godot code: https://www.spritecook.ai/blog/boids-flocking-birds-fish-2d-game

More game techniques

All techniques