Boids
Simulate classic boid flocking behavior on a list of transforms.
This action combines three steering rules:
- Separation keeps boids from crowding together.
- Alignment steers boids to match nearby movement.
- Cohesion pulls boids toward the local group.
You can also add obstacle avoidance, keep boids inside soft bounds, and constrain movement to planes like XY for 2D or XZ for 3D.
Parameters
| Parameter | Description |
|---|---|
| Boids | The list of transforms to simulate. |
| Axis | Which axes movement uses, such as XY, XZ, or XYZ. |
| Neighbor Radius | How far a boid looks for neighbors for alignment and cohesion. |
| Separation Radius | How close boids can get before they push away from each other. |
| Separation Weight | Strength of the separation steering force. |
| Alignment Weight | Strength of the alignment steering force. |
| Cohesion Weight | Strength of the cohesion steering force. |
| Avoidance Weight | Strength of obstacle avoidance steering. |
| Max Force | Maximum steering acceleration. |
| Initial Speed | Starting speed for newly initialized boids. Use 0 to start at max speed. |
| Max Speed | Maximum movement speed. |
| Min Speed Fraction | Minimum speed as a fraction of max speed. |
| Randomize Start | Randomize initial movement direction for each boid. |
| Align To Velocity | Rotate each boid to face its current velocity. |
| Angular Speed | Maximum turn speed when aligning to velocity. |
| Local Forward Axis | Which local axis should face the travel direction. |
| Use Obstacles | Enable obstacle avoidance settings. |
| Obstacles | Optional list of obstacle transforms to avoid. |
| Obstacle Avoid Radius | Distance where boids start steering away from obstacles. |
| Obstacle Radius | Fallback obstacle size when colliders are not used. |
| Use Bounds | Enable soft world-space bounds steering. |
| Bounds Min | Minimum corner of the allowed area. |
| Bounds Max | Maximum corner of the allowed area. |
| Bounds Margin | Distance from the bounds where inward steering begins. |
| Bounds Weight | Strength of the bounds steering force. |
| Lock Unused Axes To Zero | Keeps unused axes pinned to zero, which is useful for 2D-style setups. |
Example
- Add your agents to a
Transform List. - Set Axis to
XYfor a 2D flock orXZfor ground-based 3D movement. - Start with a larger Neighbor Radius than Separation Radius.
- Tune the three weights until the flock spreads, regroups, and turns the way you want.
- Enable Use Bounds if you want the flock to stay inside an area without hard clamping.
Notes
- This action moves the listed transforms directly every frame.
- Inactive GameObjects in the boid list are ignored.
- If Align To Velocity is enabled, rotation updates are based on the current movement direction.
- Soft bounds steer boids back inward near the edges instead of snapping them.