Trying to replicate (albeit unsuccessfully) the phenomenon of boids using Ursina in a naive manner.
Please install the Ursina module before running the code. More about that here.
The premise for this simulation is the following (Please refer the above code too, where it has been explained in a much better way than I am going to here):
- Each boid has to remain within some boundary. If it goes beyond a certain distance, the boid has to “turn” back.
- There must be a speed limit, and if the boids reach this limit, then their speed must not increase beyond that.
- If a boid comes really close to another, then it must be slightly” repelled away so that they don’t collide.
- Each boid has a visual range, and if there are other boids within this range, then the boid will move towards the centre of mass of the boids within it’s visual range.
- Also, the boid has to adjust it’s speed so that it moves in almost the same speed as the other boids in it’s visual range,
This is done in order to learn Ursina, and also probably create some new and interesting simulations.
- As of yet, the code is very inefficient, if the number of boids is increased beyond 20, then it starts getting choppy.
- Couldn’t figure out a way to rotate the boids in their direction of motion. Need to work on that.
At the beginning:
After some time:
Here the number of boids is 40, so the fps is comparatively low.
- Reduce complexity as the distance function is called almost 4*(number of boids)^2 times.
- Maybe attach an invisible sphere with a collider so that the computation load is reduced.