Documentation
    Preparing search index...

    Function separation

    • Separation (§12 flocking): steer away from crowding neighbours.

      repulsion = Σ (position − neighbour.position) / |position − neighbour.position|²
      desiredVelocity = normalize(repulsion) · maxSpeed
      

      Each neighbour contributes a unit vector away from it, weighted by 1 / distance, so close neighbours dominate distant ones — the standard inverse-distance falloff. The neighbour set is the neighbourhood (see the module note); a neighbour exactly on top of the agent has no direction to push along and is skipped rather than producing NaN.

      With no neighbours — or with contributions that cancel exactly — the result is the zero vector, not a braking −velocity. "Nothing to avoid" must be an abstention, or a weighted blend of behaviours would silently brake whenever the flock spread out.

      Parameters

      Returns Vector3