Coding Adventure: Boids

1.7M views · 7 years ago · tutorial · intermediate · evergreen

Sebastian Lague builds a boids flocking simulation in Unity, explaining the rules that produce flocking behavior and how to scale it up with parallelization on the GPU. It is one of his Coding Adventure videos, with a companion code repository.

HN people recommend it as an excellent, approachable introduction to boids and to strategies for handling many simultaneous queries in a simulation.

“Highly recommend, especially his older videos on simulations.”

6 comments from Hacker News

X
@Xevion2025 · in “Show HN: Genetic Boids Web Simulation”
I learned about Boids when I was 16 thanks to Sebastian Lague's amazing video on it: ▶ this video Highly recommend, especially his older videos on simulations.
RecommendsView on HN
L
@LarsDu882023 · in “Article reply “Godot is not the new Unity” from Juan Linietsky (BDFL of Godot)”
It's hard to evaluate this without seeing a screenshot of your game, but 360 raycasts per bot per frame for a basic 2d game is INSANE. It sounds like you are trying to query every angle in every direction for every character. This is madness. I have a 3d space game in Unity which uses raycasts for navigation. Each ship fires a maximum of 1 navigation raycast per frame with a sweep pattern. In addition there are anti collision thrusters placed around each ship which fire roughly every second in a staggered pattern to prevent ships from getting stuck In my fully 3d game, that's effectively ~1 raycast per frame per enemy. To locate hostiles, each ai character scans a runtime set of potential hostiles and does a line-of-sight query roughly once every 5 seconds. There definitely is another issue going on here with your setup that is independent of the extreme overhead in Godot. I would recommend Sebastian Langue's excellent boids video to get a sense about other strategies to deal with these types of queries: ▶ this video
RecommendsView on HN
b
@banana-slug2020 · in “Boids”
Nice boid-related tutorial: ▶ this video
RecommendsView on HN
j
@jonbaer2020 · in “Boids”
Boids in 3D Unity: link and the excellent related video ▶ this video
RecommendsView on HN
3
@3l3ktr42019 · in “Simulating flocking behaviour with boids [video]”
Submitted the video to Hacker News.
RecommendsView on HN
X
@Xevion2025 · in “Show HN: Genetic Boids Web Simulation”
Awesome work, the green terminal style is really cool. And the fact that it's just Vanilla JavaScript, HTML & CSS is a pretty cool touch. I would've produced something a tenth the style with 10x the complexity Just some ideas/suggestions: - Better colors: maybe genes can influence colors a bit? The random colors aren't that great, they're good though for making all the boids distinct. - Zooming: Scroll the mousewheel to Zoom In/Out, drag to move around - Interactive: Click on a Boid, have it be followed around using zoom! - Time controls: Not just framerate, but a % multiplier on simulation speed. - GPU Refactor: I don't think you're doing any of this yet, so maybe optimizing for a GPU-based speedup would be cool? See if you can reach 10,000 boids! Sebastian Lague's video goes into parallelization, just not in JavaScript: ▶ this video
CitesView on HN