Virtual Fish Tank
Sample Boid Behaviours implemented as a simple Fish Tank simulation.
Use alphanumeric keys or drop-down to change modes
1. Seek - hold LMB to make Boids accelerate in the direction toward the mouse. RMB to make them Flee (accelerate away from the mouse)
2. Pursue - hold LMB to make Boids accelerate specifically to align their velocity vector toward the mouse. RMB to make them Evade (point velocity away from mouse). The difference between Seek and Pursue is most visible when moving the mouse in a circle. Pursue will follow the mouse trajectory much more closely. Pursue uses the concept of a "goal velocity" and tries to achieve that.
3. Arrive - press LMB to drop a piece of food in the tank. The simulation does the following. For each Boid, search for the nearest piece of food within a range. If found, attempt to Arrive at that piece of food. Arrive uses Pursue, but limits the magnitude of its goal velocity when getting closer to the target point, scaling it down linearly as distance is between a defined maximum and minimum radius.
4. Obstacle Avoidance - press LMB to drop an obstacle in the tank. All Boids use four raycasts to detect collidable objects ahead of them that are slightly above, below, left, and right of its current trajectory. If a ray on the left hits something solid, the Boid will steer to the right to avoid it. If on the bottom, it will steer up, etc. If all rays hit something solid, it means the Boid is facing a solid wall, and it will steer backwards instead. Boids apply this to all objects, and the boundaries of the fish tank.
Spacebar will reload the scene.
Leave a comment
Log in with itch.io to leave a comment.