#NVJOB Simple Boids (Flocks of Birds, Fish and Insects)



#NVJOB Simple Boids is a simulation of the behavior of flocks of birds and fish.
This technology is not real Boids, it's pseudo Boids (not mathematical model), but the basic Boids rules (separation, alignment, cohesion) are followed.

The approach implemented in this asset is not classic. This is not the same thing that Sebastian Lague did in his video. Sebastian Lague did the real Flocking Simulation, and I did the imitation.

#NVJOB Simple Boids allows you to create many flocks and many objects in flocks, and it is all controlled by one script. I got good performance by calculating all the flocks in one script, but nevertheless, if you plan to use tens of thousands of birds, this will certainly affect the performance decrease.

Animation of birds, fish and butterflies implemented using shaders. The asset includes two shaders, one for birds and butterflies, the second for fish. Shaders based on #NVJOB NX Shaders.

Features:

- One script for all flocking.
- Good performance.
- A large number of flocking objects.
- Random behavior.
- Customization for different types of flocks.
- Reaction of flocks to danger.
- Animation implemented using a shader.

For Unity version of at least 2019.1.8 (64-bit)
Current version 1.1.1
Download from Unity Asset Store Download from GitHub Download from Itch.io Download Techno Demo (Itch.io) Report a Problem / Issue Tracker / FAQ

Information

There are five examples in the asset, for understanding the operation and settings.
I recommend importing this asset into a new project. Study the operation of the asset and copy the components you need to your project.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

Bird Boids - 2000 birds divided into 8 flocks, with partial migration.
Butterfly - 500 butterflies, divided into 10 flocks, with partial migration, increased miscibility. High performance.
Fish and Bird Boids - 1500 birds divided into 6 flocks and 1500 fish divided into 8 flocks. Two scripts, for birds and for fish.
Fish Boids - 3000 fish, two types, divided into 6 flocks. Two scripts.
Fish Boids Danger - 2100 fish, three types, divided into 6 flocks of birds. One shark in the role of danger. 6 scripts (danger is determined by one script, for one flock).

The scenes use a large number of birds and fish, it is beautiful, but impractical. Use no more than 500 birds and fish in the scene, this amount will almost not affect performance.
See the Butterfly example, 500 butterflies in the scene have a very high FPS.

Component Settings

Description of component settings. There are already two prefabs in the asset, with settings for birds and fish, you can also explore examples.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

General Settings
Behavioral Ch - random time of changing the behavior of flocks and objects in a flock. Set the minimum and maximum value.
Debug - enable flock target position display.

Flock Settings
Flock Num - the number of flocks within this script.
Fragmented Flock - scatter of targets for flocks, relative to the object to which the component is attached.
Fragmented Flock Y Limit - limit the scatter of targets along the Y axis. This is a multiplier (this value * fragmentedFlock.y).
Migration Frequency - frequency of migration from one flock to another, from 0 to 1. The higher the value, the more often the migration.
Pos Change Frequency - frequency of change position of target for flock, from 0 to 1. The larger the value, the more often the position changes.
Smooth Ch Frequency - smoothing the change in position of the target for flock. This is necessary so that there is no sharp change in the direction of movement of the flock.

Bird Settings
Bird Pref - prefab object that will be in a flock.
Birds Num - the number of objects in total in all flocks.
Bird Speed - the speed of objects in flocks, this value is multiplied by the random speed of a particular object (from 3 to 7).
Fragmented Birds - scatter of objects inside the flock.
Fragmented Birds Y Limit - limit the scatter of objects within the flock along the Y axis. This is a multiplier (this value * fragmentedBirds.y).
Soaring - soaring object. The lower the value, the more soaring. For sharp turns, increase the value.
Vertical Wawe - swinging an object along the Y axis.
Rotation Clamp - enables the restriction of rotation of the object along the X axis. Prevents a strong turn up or down. This option imposes certain costs on performance.
Rotation Clamp Value - value of the rotation angle limit up and down.
Scale Random - local random size of the object in the flock. Set the minimum and maximum value.

Danger Settings
Danger - enable danger detection. Also, one collider is turned on, for the hunter to detect flocks. Danger is determined by one script, for one flock. See the "Fish Boids Danger" example.
Danger Radius - radius of danger detection.
Danger Speed - change in the speed of objects in a flock when danger is detected. This is a multiplier (this value * birdSpeed).
Danger Soaring - change in the soaring of objects when danger is detected. This is a multiplier (this value * soaring).
Danger Layer - LayerMask of the object being the danger.

Shaders Settings

The asset includes two shaders, one for birds and butterflies, the second for fish. I did not combine the shaders into one, because the animation in the shaders is not the same.

Important! You must set the Render Queue to more than 2500 if you are using the Forward rendering path (please read "Performance Tuning" carefully).

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

Bird Flapping
Flapping Speed - the speed of flapping wings.
Flapping Y Power - the power of flapping wings along the Y axis.
Flapping Y Offset - offset of flapping wings along the Y axis.

Flapping X Power - the power of flapping wings along the X axis.
Flapping X Offset - offset of flapping wings along the X axis.

Flapping X Center Indent - Indent in the center along the X axis.

Flapping Z Power - the power of flapping wings along the Z axis.
Wave Y - the general oscillation of the object along the Y axis.
Wave Y Speed - the speed of the oscillation.
Butterfly - enable butterfly animation mode.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

Swimming Fish
Swimming Power - the general power of swimming.
Swimming Scale - the general wavelength.

Swimming Speed - the general swimming speed.
Wave Body - wave amplitude, XZ axis.

Wobble - swing locally along the YZ axis.

Wave Y - the general oscillation of the object along the Y axis.
Wave Y Speed - the speed of the oscillation.
Script Control [HideInInspector] - change the speed and direction of the animation through a script. This parameter is used optionally. For more details see the shark script from the "Fish Boids Danger" example.

Performance Tuning

- Use no more than 500 birds and fish in the scene, this amount will almost not affect performance. A noticeable drawdown in performance starts with 2000 objects.
- Do not use shadows for prefab objects unless necessary.
- Use models with as few polygons as possible.
- Important! Do not enable the "Rotation Clamp" option. This option uses eulerAngles twice. See "BirdsRotationClamp" for details.
- Important! If you expose the Render Queue of the shader over 2500, make sure that the Render Queue for different materials for the prefabs is not the same, for example 2501 and 2502.

- Important! Enable "enable GPU Instancing" in the material settings.


Model Creation


Asset already includes several models (three fish models, one bird model and one butterfly model).
In fact, you can use any model, see the example "Fish Boids Danger", the shark is animated using a shader.
Creating Models in Blender

Place the cursor in the center (Shift + S -> Cursor to Center), create a cube.
Now this cube is the border, make sure that the size of your model does not go beyond the boundaries of this cube.

Center the object (Shift + S -> Selection to Cursor (Offset)) and rotate the object along the axes, as shown in the image.
Lift the model slightly.

Apply object transform (Ctrl + A).
Export the model to FBX with the specified parameters.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

#NVJOB Simple Boids (Simulation Flock). Free Unity Asset.

License

This project is licensed under MIT License
(C) Copyright 2016-2020 #NVJOB
Nicholas Veselov Unity Game Developer
Николай Веселов Unity Разработчик Санкт-Петербург