I created a flocking algorithm and incorporated my previous obstacle avoidance code into it as a type of steering. I had to modify how my previous obstacle avoidance code worked to get a steering vector instead of simply rotating the boids.
For my method, I took the contact normal from each raycast’s collision, drawing a ray from the point of collision in the direction of the contact normal a variable distance, and steering towards this point. In the event of multiple rays colliding, it adds each resulting vector together and normalizes.
(Color code)
Cyan: Boid raycasts
Blue: Ray collision
Red circle: Final target to steer towards
Initial results were promising but there were a few edge cases that needed solving, like detecting corners and smoothing out the rotation. For the corner fix, I tried a few things like steering towards the combined normal of the two planes meeting or just forcing a left turn, but they all had caveats that made the interaction even worse so I simply just turn the boid 180 degrees and reverse its velocity when encountering a corner.
Video demonstration
: https://drive.google.com/file/d/1V9t4xRcog62Nc7vcpAZnuYUq4_KhRVvN/view?usp=sharing
Comments