Aller au contenu

pFlock Node

By Kriss Norde

pFlock simulates flocking behavior (Reynolds' boids algorithm): particles move closer together while keeping a minimum distance between them. The result: believable swarms of birds, fish, ants and crowds. Combined with pFollow, it gives you intelligent collective motion.

Overview

pFlock implements Craig Reynolds' boids rules:

  • Cohesion: each particle moves closer to the neighboring group.
  • Alignment: each particle aligns with the average direction of its neighbors.
  • Separation: each particle avoids close collisions.

Combining these 3 simple rules produces complex emergent behaviors - that is the magic of flocking.

Where to find this node

  • Effects Library: Tools > Particles > pFlock
  • Quick add: right-click in the Node Editor → Add Tool > Particles > pFlock

Inputs

  • Particle Input (orange) - incoming stream.
  • Region Input (green/magenta) - optional. Limits flocking to an area.

Setup

School of fish:
pEmitter (fish sprite) → pFlock (standard)
                         → pFollow (animated leader)
                         → pRender

Flock of birds:
pEmitter → pFlock (Flock Number 8-10 for cohesion)
        → pDirectionalForce (wind) → pRender

Walking crowd:
pEmitter (ground level) → pFlock (high Separation)
                       → pFollow (destination path)
                       → pRender

Boids parameters

Flock Number
Number of neighbors each particle takes into account. Higher = stronger cohesion (tight group). Low = nearly independent particles.
Follow Strength (Alignment)
Intensity of the desire to align with the average direction of the neighbors.
Attract Strength (Cohesion)
Force pulling toward the center of the neighbors (when too far away).
Repel Strength (Separation)
Repulsion force when two particles are too close.
Minimum / Maximum Space
Ideal distance between particles. Min = minimum distance before repulsion. Max = maximum distance before attraction. Tight ranges = an organized group.

Use cases

  • A coherent school of fish - pFlock + pFollow toward a moving target = a school that follows a leader while keeping its shape.
  • A flock of birds - standard pFlock + pDirectionalForce (wind) = a flock migrating naturally.
  • A swarm of bees / insects - high Flock Number (strong cohesion) + pFollow toward a point (attracted by a light) = a swarm around a point.
  • A moving crowd - high Separation (avoids collisions) + pFollow toward a destination = people crossing a square.
  • Intelligent collective behavior - simulates "group intelligence" without explicitly coding AI.

Tips

  • pFollow + pFlock combo = a living swarm - pFollow drives the destination, pFlock handles the interactions between particles. Together = believable emergent behaviors.
  • Balance the 3 forces - Attract too strong = particles merging. Repel too strong = an explosion. Alignment too strong = rigid motion.
  • Flock Number 8-10 as standard - follows the original Reynolds rules. More neighbors considered = more cohesion.
  • Watch performance - pFlock evaluates the neighbors of every particle = O(N²). Above 500 particles, performance drops.
  • For a real crowd simulation (humans with individual AI), consider dedicated software (Massive, Golaem).