A swarm simulation algorithm for Unity Engine. Based on Craig Reynolds boids-Algorithm.
There is no shared memory between multiple agents. The swarm movement is created through aggregation of the individual behaviour. The individual agents act based on a few movement patterns defined by Craig Reynolds in Steering Behaviors For Autonomous Characters.
This implementation supports the following steering patterns:
- Seek
- Arrival
- Wander
- Cohesion
- Separation
- Alignment
- Obstacle Avoidance (using a different concept)
- Hide
- Flee
To integrate this into your project simply place the agent-script and the behaviour-script somewhere inside your project (in the same folder).
If you wish for some demonstration you can put the whole intergrate the whole asset-folder) into your project assets. Inside you will find a sample-scene for demonstration purposes and some textures. If you need an example for possible swarm agents, take a look at the prefab-folder.
Any gameObject
can be turned into a swarm agent.
The only requirement is that the following components are attached to the parent-object:
- the agent-script
- a
Rigidbody
- one or multiple
Collider
's of any size or form withisTrigger = true
(used to detect nearby enemies)
You can customize the behaviour of any individual agent by adjusting values in the inpector.
The Ratio-Tab lets you configure how the different steering behaviours are mixed to create the agents movement:
Example: for agents to only use the "Wander" movement pattern, set wanderFactor to 1 and all other factors to 0.
For fine-tuning the different movement patterns can also be customized:
Example: use Arrival Slowing Distance to customize the distance to the target, at which the agent starts slowing down.
Click here to watch a demo video.
- Stylised Submarine (only character and animations were used)
- Sardine (only character and animations were used)