Code AI Swarms, Flocks & Hordes | Boids Scratch Tutorial
Learn how to code Boids AI in Scratch (originally created by Craig Reynolds in 1986 to simulate the realistic flocking behaviour of birds). But this can be used for swarms of aliens, hordes of Zombies or waves of enemy NPCs, so you too can bring amazing artificial life simulations in to your games. Follow the basic 3 steps, Separation, Cohesion, & Alignment and get 50+ boid clones interacting with each other and with your mouse - Now Scratch on Guys!
My tutorials are for all budding game & software developers using Code Blocks. Full of useful Scratch Tips and coding goodness for beginner coders to advanced Scratchers!
🐱 Scratch Studio for this tutorial - scratch.mit.edu/studios/31985...
👀 Quick and Fun Tutorials - • Quick and Fun Scratch ...
⭐ Channel membership with perks - / @griffpatch
❤️ Scratch Addons - scratchaddons.com/
📹 Video Editing Software - techsmith.pxf.io/c/2682566/50...
-------------Video Chapters-------------
0:00 Intro
1:49 Draw a Boid
3:01 Clone the Boids
4:38 Get them moving
8:10 Pointing a sprite towards a vector (speed x, speed y)
9:53 Speed Levelling
13:51 Sight - Awareness of other Boids using Lists
16:58 Separation / Avoidance
23:23 Cohesion - Herding / Sticking together as a group
26:48 Alignment - Heading in the same direction
30:05 Show Hide the UI Sliders
31:34 Avoid Mouse?
32:58 Outro
Пікірлер: 1 000
Are you settling them to a random colour as they clone or changing colour by x as they clone. Or will they detect colour of boids in range and shift to that colour
@griffpatch
Жыл бұрын
Ah, in my new version I change their colour when they move off screen and appear on the opposite side. But the colour I set is based off timer * 10 (or something) + an offset. The offset is 0, 50, 100 or 150 depending on which edge it goes off. I also set the brightness to a random number at the start + - 10 or something
@vistaman69
Жыл бұрын
how did you comment 19 hours ago when he posted it 16 minutes ago
@UltronZX
Жыл бұрын
@@vistaman69 wait thats true
@nilzethalves6507
Жыл бұрын
@@UltronZX i'ts bcuz the video was first for members
@_KDP
Жыл бұрын
@@nilzethalves6507 yep
When he said "it's scratchin' time!" and scratched all over the screen, it left 5 tears on my right eye. Truly one of the game developing moments of all time
@sdbadik
Жыл бұрын
Best comment i've seen under any Griffpatch video
@The_Asasd
Жыл бұрын
Personally, I liked the part where he says "it's thing of thing blockin' time!" more.
@kasonmakesstuffs
Жыл бұрын
@@The_Asasd nah its when he said "Its Make a new variable'in time!"
@progCan
Жыл бұрын
@Ian Gustafson lmao
@jaxonmays
Жыл бұрын
I see these comments, EVERYWHERE I GO, AND I AM LOSING MY MIND
After roughly 10 minutes of listening to this tutorial at 2x speed, the word 'boid' / 'boids' is said a grand total of 145 times! That's a lot of boids!
@griffpatch
Жыл бұрын
Amazing
@1080GBA_SC
Жыл бұрын
imagine counting for 10 minutes then realizing someone counted it already (its a joke)
@imjustheretocomment492
Жыл бұрын
@@1080GBA_SC lol
@redbirb
Жыл бұрын
you didn't have to count, you could've thrown an AI at it! AIs LOVE counting and definitely won't mistake any words other than boid/boids as boid/boids! (The AI probably will mess up xD)
@1080GBA_SC
Жыл бұрын
@@redbirb yes but you need to know how to code it
The fact that griffpatch is basically the only scratch tutorial guy (thats useful anyway) means Scratchy is pretty much canon at this point
19:54 "More variables! I need more variables!" -Griffpatch (the variable master)
@jamesnicolailorenzo9714
Жыл бұрын
he sounds like an ai
@MaxwellCatAlphonk
Жыл бұрын
Tanger
Boids were always fascinating to me in grad school. So simple, yet such complex (and mesmerizing) group behavior.
@griffpatch
Жыл бұрын
Yes indeed :D - And a prime subject for learning some optimisations skills going forward if there's interest!
@Resseguie
Жыл бұрын
@@griffpatch I particularly enjoyed studying emergent behavior and cooperative tasks in these types of systems... i.e. tweaking the simple rules to cause the individual agents to solve some particular task such as building a bridge like ants.
@DUMB_PERSON_NEAR_ME
Жыл бұрын
@pixel Smiler official good idea
@electro9442
8 ай бұрын
69 likes
I once saw this in an episode of "Coding Adventure", I'm so excited to see this in Scratch!
@redbirb
Жыл бұрын
TBH I wanted someone to make this into a scratch tutorial, and naturally, Griffpatch rose to the occasion
I still can't believe how easily Griffpatch can explain complex concepts and make us want to program and improve our games even more! Continue Griffpatch🥳
The fact that Griffpatch pretty much played the whole outro music is awesome! Just some Epic Music! I love your tutorials Griffpatch! I’m looking forward to finally make an RPG from your tutorials!
Wow! Your direction trick is amazing! A while ago I used trig to point in the direction of movement and it was such a pain, but I got there in the end.
I can't comprehend the amount of creativity and problem solving skills you have...but I still love it!
That was a lot of very clever math. I personally found it genius the position difference to actual distance to make a straightforward math equation to calculate how tight the turns need to be.
This is insane. I'll try to implement it with pygame and python. Thanks for such a interesting lesson ☺
Griffpatch, you are genies!😄 Thank you for this wonderful tutorial!
Thank you soooooo much for this tutorial, finally i know how to check for nearby clones! You are the best :D
I had a great time coding while listening to you explain how it works. Thank you for your hard work. Keep it up!
@griffpatch
Жыл бұрын
Glad it helped!
oooh im totally gonna use this to add leeches to a game! Edit: give each object a different "weight" where the food (to distract them) has the most, the player in the middle, and the critters themselves the least. Maybe even negative values for stuff the are repulsed by... Tons of cool stuff to do with this project!
@babascorner4755
9 ай бұрын
Good idea! I would love to see that game
I counted around 101 mentions of boid. But I also lost count somewhere around cohesion... Ah boids! I had a not so great game jam submission where you would have minions that acted like boids, and you could direct them towards enemies. That was around when Sebastian Lague posted their own video on Boids. Each step just makes you more excited for the next!
Out of all the tutorials, I would've never expected boids!
YES ! A VIDEO ! Love you're videos ! Continue like that !
I was searching for this weeks ago but couldn't find one that's easy to understand I even tried making my own but still failed And I just gave up Definitely didn't expect a tutorial for this But I'm glad you made one ❤️
Omg this is amazing! Thanks Griffpatch 💪 You always surprise ne and teach me new things 🌟
@griffpatch
Жыл бұрын
My pleasure!! So glad you enjoyed it :D
@MaxwellCatAlphonk
Жыл бұрын
@@griffpatch Hi
omg ive been waiting for something like that for ages thank you
Wha- I-… this is incredible! Impressive as always
I've never used any of your scratch tutorials before because they seemed very hard to do, but this one actually was useful, thanks griffpatch! edit: help the boids are on the top of the screen and not on the middle like what you made
Congratulations griffpatch 🥳🎉🎊 You just hit 400,000 followers! That's not a small number! We all hope that you do your best and keep growing and keep boosting the number. We believe that you can break the limits of scratch. All the best! Sincere regards, Dipusen
@-tylerrodgers-
Жыл бұрын
**makes a 5635638456456d game in scratch** *It's really simple!*
@dog_2
Жыл бұрын
@@-tylerrodgers- wth
I have just started back on scratch again after a break for my mental health and your videos have made my day
@griffpatch
Жыл бұрын
yay!!!
Dude your videos and projects are SO GODDAMN AMAZING!! You deserve more subscribers!
Thanks griffpatch for this tutorial! You always make my day better
This helped me in one of my games i used the direction trick thank you it helped me after 2 hours of raging not being able to get the directions to be able to work this helped me for my game!
A couple of tips. 1. If you add a "set color effect to boid count *5" line to the bottom of the Calculate subfunction, the boids will change color based on the number of other boids in the flock. 2. If you want a more visible "avoid mouse pointer" function, multiply the range by 1.5 and the negative separation by 10: the boids will then rapidly flee from the mouse pointer, like fish fleeing a disturbance at the surface of the water. 3. By using separation rather than negative separation, you can also get the boids to swarm towards the mouse pointer, rather than away from it.
if you use the script at 9:31 but instead of randomly positioning the boids, you set them all to the centre, you get a really cool pattern
@griffpatch
Жыл бұрын
That's interesting :) - What pattern do you get?
@dazcar2203
Жыл бұрын
@@griffpatch the boids basically explode outwards, and then start coming together in various groups until they all rejoin in the centre.
I just got this working in python (unfortunately couldn't figure out angle to a coordinate in order to change the direction of boids, i'll look into that soon), and it was so satisfying when i first saw them align to each other!
@connorclub6244
Жыл бұрын
Update: I went to the scratch wiki for "Finding Direction with Velocity" which was actually what I needed. It seems to be a bad approximation (seems to be always 0 or -90 for some reason) but its not bad.
@connorclub6244
Жыл бұрын
BETTER UPDATE: It turns out I was being a goddamn idiot and already had the CORRECT code in there, I JUST FORGOT TO USE IT
@scotlzngd4498
9 ай бұрын
For the direction you can use math.atan2(-speed-y, speed_x) to get the angle in radians of the boid
This is so useful! Not just for scratch but for others! I made a python boid that has the same effect and it is amazing
It's incredibly outstanding on how he's used his talents for nine years straight just to help us. What a good guy !😊
@SIG7Pro
Жыл бұрын
Agreed.
I love the "well, hurra!" In the begging!! It makes me so exciting!!
Hey Griffpatch, I would like to ask you if you could do something on different types of procedural terrain generation like wavefunction collapse and perlin noise. I find procedural generation very interesting, and I think your viewers would love to see it, and we could end up with some really cool games! Thanks for reading! :D
Always love boids. Looks beautiful with that trail version. Are you just stamping the previous frame with a transparent fill?
@griffpatch
Жыл бұрын
Yes that's right
@liamisakid
Жыл бұрын
@@griffpatch Funut also made a Boids Project :)
@schnagli
Жыл бұрын
Hi Funut! Are you planning To do KZread-videos again?
I could remix this to make an awesome idle game! I was so glad when you said you had a little trick about the angle calculator, because I knew you would do something like I did too, by using another sprite.
Wow thank you so much for this video, I've always wanted to make something like this, thanks for the tutorial! :D
Hi griffpatch, I have been making a capture the flag like game and this tutorial could be great for the AI! Two questions though: 1: How do I make them go TOWARDS the other team's members? 2: How could I adapt this tutorial to make it scroll on the X (The game only scrolls on the X)
@minecraftjack6439
Жыл бұрын
2. Replace the x position reporter blocks with a variable for the x. Have another variable for x scroll. Then in the go to position block, use x+the scroll x instead of x positon+speed x
@SIG7Pro
Жыл бұрын
For question 2, probably just don’t do anything for the y values
this is such a cool simulation! it looks so cool! thanks griffpatch.
WOW! this so cool, thanks for the tutorial griffpatch!!
I love that editing style!
Finally a new project! Way to go!
As a Scratch lover, this is really satisfying.
i didnt do the code for hiding and showing sliders. instead,I coded an options button. thanks for this tutorial ,I loved it!!!!
I always like stuff like this! I'm ready for another great griffpatch video!
@griffpatch
Жыл бұрын
Me too... I love simulations and particles, and movement :)
@theanomynusguy
Жыл бұрын
@@griffpatch make a 3d version of conways game of life
WOW! this is sooo AMAZING! thank you soooo much griffpatch!
@griffpatch
Жыл бұрын
No problem!!
*Amazing Work! Keep it up!*
I recently saw Sebastian Lague's video on this, and wanted to recreate it in Scratch! Thanks!
Oh man this was worth the wait just for the hiding and showing variable script
Just appreciate how great Griffpatch's voice sounds!
Wow. Thnak you so much. I was going to write a program in python. But it's a bit hard for me. This video helps a lot to understand the concept.
Havent watched it yet but by the thumbnail this looks AMAZING!
I thought it's going to be an unboxing video. well, I unboxed a new type of simulation in scratch. good scratching sir
Wow! This is real dang. Loved it.
That is amazing! Very great job!
Finally, I can use this and know how to. Thanks
this is the smoothes boids i ever seen it makes my eyes better too see .. and im not here to say that but thanks for making the smooth better for me to use i said it didn't work even tho the code was wrong ;-; but now it works but i still have to confugire the varaibles
This is probably your most satisfying tutorial lol
Thank you so much for this!
I’m not gonna do it, but this is honestly amazing and satisfying. (The fact that two giant circles mixed to make another huge circle)
@griffpatch
Жыл бұрын
I loved that too lol
@Blue-gy2it
Жыл бұрын
@@griffpatch WAIT *WHA-*
Wow 🤩! Your tutorials helped me a lot!
@griffpatch
Жыл бұрын
Happy to hear that!
@tunafish928
Жыл бұрын
@@griffpatch Also I am trying to get my Mario platformer series done
Thanks!! This is really helpfull. I'll use it for my Bee game! :D
You said you were taking a break from video to make a game, and I thought that was the RPG game you showed on video. But you also made a project on your scratch account! 🔥 It is awesome and I hadn't even noticed him!!! 😱😱😱😱 You could make a short video on it like for the MMO platformer ? 🌟 (In addition to the other videos, or instead of a video if you want to take a video break for a week for example)
I have been trying to make an ai that slightly moves and this will help with the zombies in my project zombified thanks griffpatch for making this tutorial
So excited!
Wow you went from projects dedicated to kids to such complex algorithms. I guess I'll wait for your next AI project in scratch 😅
Hello! It would be cool if you made a tutorial on neural networks (machine learning) they would be really adaptive to amy environments given you train them well. Its a pretty complex topic, but looking at how well you handled boids, it won't be a problem for you :) also its a really interesting topic to dive into, so you really should try it out ;)
This was like the best thing to watch after I got a commenter trying to make me stop using Scratch to draw scenery for my animation videos. Idk like some zombie game is what comes to mind for me (duh)
I just finished the project, and it turned out EPIC (ty griffpatch) but I think now I have a fear of variables
@EthanCarey-np6ue
Жыл бұрын
WHY WONT MY CLONES WORK
came back from school and i got something Great!
Nice video as always :) keep it up!
@griffpatch
Жыл бұрын
Thanks, will do!
Ohhhh! I love the project in the outro! I which you could share them! It is so fascinating! I guess you played it in turbowarp!
@griffpatch
Жыл бұрын
Yes it was in turbowarp, but it also had my optimisations that allow the project to run x5 faster than it does in this tutorial alone.
That was very cool Griffpatch!!!! Can you make a physic quick and fun tutorial?
Woah griffpatch! That looks awesome!
great, just wonderful! I think I could master it and use it in my games! (:
a lot of my programming knowledge comes from watching giffpatch explaining how to make it in scratch and then me using the same concepts to use it in other languages.
great as always! And in only one episode
The way you popped eyes on the boids was cute not gonna lie
It's funny how your stuff helps me (I literally port to lua)
It is lucky that your'e a scratcher, without you... WE WOULDN'T GET EXCELLENT PROJECTS LIKE THIS!!!
Hey, great video! Really helped with a simulation I am making. I'd like to ask how to make custom time so with a variable time can run faster/lower. It's the only thing I haven't figured out yet xd
I like how you say "For All Sprites"
I wanna thank you for this useful content
Thank you for publish it.
I recreated your exact setup at 0:26 and if you want to achieve maximum overdrive you just have to use these settings: target speed 5 resolve 0.01 range 150 separation 0.2 cohesion 0.1 alignment 0.01 Then turn on turbo mode for a couple seconds
congrats to 400k on scratch griffpatch!
@griffpatch
Жыл бұрын
Thanks
Hey Griff! Amazing tutorial I have an idea for a game that you could maybe make a tutorial for and it would be useful to create tons of new and exciting games! It would be tile based like the Mario game but you could move around like an RPG. You would need to destroy trees to make pallets (basically tiles made out of wood) to make a small base. Then, after 30 seconds or so, a few zombie hordes appear from offscreen to attack you. You would need to hit them a few times to kill them, and every horde would be stronger, faster and bigger. By the way, are we gonna see more Mario tutorials? the last one was part 20 where we made the Star and the finish goal, but so many new things could be added, like underwater levels that you can swim on, pipes that take you to other sub-levels, the tanooki leaf (which frankly was the best item of SMB3 that really adds another dimension to the game) and other ideas from the comments. It's probably really exhausting for you to make all those videos on the same topic though, so do it on your own pace. Thanks for all the amazing tutorials, they were the ones that brought me to Scratch!
Congrats on 400,000 scratch followers!
Hello GriffPatch, great video as always
@griffpatch
Жыл бұрын
Hey, thanks!
Out of all the tutorials i watched i feel like this is the first time i saw griffpatch use the "distance to :sprite:" block
21:02 the most hardest math moment I've ever seen in griffpatch tutors
Like in each video, you blow my mind 😍😍 And pls in next video could you do neural network that learn to play game, in scratch of course. That would be sooooo coool !
This is so cool!
Awesome as always!!
@griffpatch
Жыл бұрын
Thanks again!
Griffpatch is one of the best coders i know
You took the words right outta my mouth.
AHHH I JUST FINISHED MY OWN VERSION OF ONE OF THESE!
@griffpatch
Жыл бұрын
Oh wow that's so cool well done! Did it go well?