This Unity project implements a boids flocking system combined with a custom Bezier path System. It uses a CPU-based docking algorithm to guide boids to dock or align with designated positions along a precomputed path.
https://github.com/payam-ranjbar/Flocking-Boids-System-Unity/blob/main/Demo.mp4
-
Flocking Boids
- Simulates natural flocking behavior using individual boid agents.
- Implements steering, avoidance, alignment, and cohesion rules.
- Uses a CPU-based docking algorithm to smoothly guide boids towards designated docking positions along a preset path.
-
Custom Bezier Path System
- Generates smooth paths using waypoints with adjustable tangent offsets.
- Bakes Bezier curves into nodes for guiding boid movement.
- Provides visual tools for path editing directly within the Unity Editor.
-
Editor Tools & Utilities
- PathEditor & WaypointEditor: Custom editors for modifying paths and waypoint tangents in the scene.
- ProbablityExtentions: Helper methods for randomization and probability-based decisions.
- SkyBoxShaderManager: Dynamically updates skybox shader properties based on scene lighting.
-
Navigation Folder
- Path.cs: Defines and bakes Bezier paths using waypoints.
- PathTraverser.cs: Moves GameObjects along the baked Bezier path (guiding boid movement).
- Waypoint.cs: Represents individual waypoints with tangent offsets for Bezier curves.
-
Editor Tools
- PathEditor.cs: Custom inspector for the path component with extra functionalities.
- WaypointEditor.cs: Enables in-scene editing for waypoint tangents.
- PathEditorView.cs: Base for further custom editor visualization features.
-
Flocking System
- Flock.cs: Implements boid behavior including movement, steering, and docking based on CPU calculations.
- FlockManager.cs: Manages global flock settings, boid instantiation, and overall simulation parameters.
-
Utilities
- ProbablityExtentions.cs: Offers helper functions for randomness and probability calculations.
- SkyBoxShaderManager.cs: Updates skybox shaders dynamically based on the directional light's orientation.
-
Import the Project
Clone or download the repository and open the project in Unity via Unity Hub. -
Scene Setup
- Flocking System:
- Place the
FlockManagerGameObject in your scene. - Assign a boid prefab (with the
Flockscript attached) to the FlockManager. - Adjust flocking parameters (e.g., speed, neighbor distance, avoidance threshold) in the inspector.
- Place the
- Bezier Path System:
- Create a new GameObject with the
Pathcomponent. - Add child GameObjects with the
Waypointcomponent to define your path. - Use the custom editors (PathEditor and WaypointEditor) for precise editing of waypoint positions and tangents.
- Create a new GameObject with the
- Docking Algorithm:
- The CPU-based docking algorithm ensures that boids can dock to predefined positions along the baked path when required.
- Flocking System:
-
Running the Simulation
Press Play in the Unity Editor to see:- Boids exhibiting flocking behavior and docking along the path.
- Movement guided by the precomputed Bezier path without runtime control over trajectory adjustments.
-
Flocking Behavior:
Tweak parameters inFlockManagerandFlockscripts to modify speed, avoidance, and alignment for varied flocking dynamics. -
Path Editing:
Adjust the Bezier step size, waypoint positions, and tangent offsets in thePathandWaypointcomponents to change path curvature and smoothness. -
Docking Algorithm:
Modify the CPU-based docking logic in theFlockscript if additional docking behaviors or performance optimizations are needed. -
Shader Management:
Customize skybox lighting by updating theSkyBoxShaderManagercomponent to suit your scene’s visual style.
- The CPU-based docking and flocking behaviors were inspired by Holistic3D's Boids Tutorial.