Pathfinding #3 - Best with grid [Game Maker Studio 2 | Advanced]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to the last of ai path funding so this is number three with the best version in my opinion the best version because this is the most complex one a little bit more setup and necessary but as you can see the conga line this is one of your comments because it's actually true it is one conga line of course you can remedy this a little bit but um they get out of uh this kind of pathfinding they get out of even the most tricky situations and then of course the update which is the best part and then as you can see works pretty nicely so if you want to know how to do this in game maker studio so this is the ultimate thing by the way i guess this is the one thing which they actually use in hotline miami not my series but i guess generally then stay tuned this is one up indie i am developer so if you like what you're seeing hey why not consider sharing liking and subscribing and why do i say that well because this is boosting the youtube algorithm that's why i'm just asking i don't say this to annoy you every time alrighty let's start this thing so what do we need for that basically just two things and opportunity is three things first of all a little controller which is just sitting somewhere wherever so we can have a nice grid and then second of all the things which you want to input so basically enemies which you want to have and then you can just put as many as you like it doesn't really matter this is then up to you and then one setup object which is sitting somewhere because we need to establish kind of a system and then on that system all the little grid enemies can ride on it so here what do we have basically everything which we need i just cleared it out so you can actually check it out and then well first of all let's get rid so you can see the whole thing so first of all on our instances or wherever we put our pathway basically this is the one object which is sitting there this is the controller so this is number one and then well our enemies already placed them so hopefully you understand what's going on i guess this shouldn't be too difficult and then let's set up our pathway so the first thing which we need to do is for example if you have this room so what you're seeing here for example here you can actually toggle a grid by itself but this is just for helping out so things kind of snap to it so um this is one thing so for example if your grid is 16 by 16 so here you can actually define it and this is nicely done i would recommend that you set up your room 16 by 16 and therefore we can apply the grid at the same kind of structure so a 16 by 60 thing so first of all what do we need first of all we need to create a grid so you can completely forget forget the depth this is just because i want to show you something in a few seconds and then what we can do is go mp grid because there is actually another grid so there's also ds grid but we're using the mp1 because this is the one which we want to formulate the mp grid and then we say create and here quite a lot of things which we need to put in and for example we can actually open this one and this is the official one then we have a lot of things which we need to put in so top left here we can just go zero and zero so what does that mean well because we want our grid to start at this point for example if you just need it at another position then you can set it up differently but i would say zero zero is definitely good and fine and then it says h cells and v cells so this means how many cells are we actually having and here because my room is set up to be um room width by uh by 16 so we can just say hey the whole room with divided by 16 and then the room height also divided by 16. and then we get the amount of horizontal cells and the vertical cells yeah that's actually right i just need to think about it and then of course it says hey how big are ourselves so they are 16 by 16 and basically we set it up and now this is basically this do nothing it's just saying like hey we create a grid so we just say grid and say and assign it to it and then for example we say like hey the grid needs to be a little bit more specific because we want our enemies to kind of go around these things so for example here just take away the walls you can see here these are instances they are called wall horizontal or vertical or whatever and then i have a higher hierarchy which is just object to all parents so basically they're all inheriting from this object and therefore we want to bounce and have this kind of as a structure and then later on you will see what i mean so basically we need something so the enemy has to go around these walls as a obstacle so therefore we just say mp grid mp grid and then add instances you can actually go rectangles or cells or whatever for example you can go input single ones but for us it's a little bit more easy we just say hey the id then my object this is of course then here wall parent because this is including all of them and then you can say like precise but for us it's not a matter for example here i gave my enemies just a rectangle i guess it's 16 by 16 is it i guess now it's even smaller so they do fit in here so once again if you're creating such a maze or whatever don't make it 16 by 16 and then the enemy the same but then sometimes they can get stuck in here and then they cannot go precisely in there that's why it's a good rule of thumb to make them a little bit smaller just one thing so basically now we have set it up basically we created our grid and then we just added the wall instances on what obstacles we're having and then basically this is pretty much done and then what we can actually do is draw that thing so we can say actually mp grid this is in the draw event draw and then our grid and now what will be happening so for example if we start it put that back on so let's start it alrighty so what you're seeing here this already is uh kind of showing you for example this is basically just already drawing the grid but as you can see it's drawing rectangles and the green ones are where we can go and then the red ones is where we're not supposed to be going so basically this is if we are drawing the grid on the screen and please don't do that because this is taking quite a lot of performance out of the game and interestingly for example if i zoom out this is actually out of the room but doesn't really matter because i kind of cheated in here with the background this is the background which is getting drawn out of that so this is where we are going and basically we just need to put it somewhere in the room and then we we can basically forgot if i forget this object pathway thing because we don't need it but let's make it a little bit more transparent to c and therefore we just go and make a draw set alpha to 0.3 so you can actually see it nicely in the room and then we just close it because we don't need it anymore alrighty so let's go into our enemies and basically plant them everywhere in the room of course don't put them on top of the wall because i guess then they are stuck and then they cannot move actually haven't checked this out but um should make sense so for that we need to make a few things so this stuff is actually working so first of all this is optional we just define a target for example for me we need to go some x and y positions of course if you just go on a specific coordinate you don't need a specific object like i'm like my player here and then you can completely forget that but here i think this makes the most sense then the next thing is we need to update our path or have one pass and therefore we create a little nice variable and say like path s for now this is doing nothing it's just adding a path into memory and then it's doing nothing with it because well that's pretty much it and then what we can do is update that path and then for example update it so for example is our if our player is going somewhere so there going somewhere then we are updating the path to it specifically but um i guess in step event this is quite resource consuming and therefore we can make it a little bit neater if we just loop the alarm and do that um just a few times and not every uh step so basically 60 times per second that's a little bit of an overkill because if you have more than one enemy let's say you're 30 or 40 or whatever then i guess this could uh well reduce your performance at some point significantly and therefore just select let's make this a little bit nicer so the first thing which we want to do is we want to loop our alarm so let's say every two seconds we are updating the position where we want to go of course here if you need a little bit more specific go with lower refresh times basically this is just updating then the next thing is we need to delete the last pass and then update it to the new one for example what isn't actually happening so for example if you just say like hey um if you just changed how the path is it's kind of wonky and therefore we just say like alrighty delete the earth path and create a new one so this is one thing and then for example we need to of course give it new coordinates where to go and then here we're just saying like hey target and now we come to the magic part i guess this is the most thing we want to write on the grid which we have created now so we just say like hey use the grid and therefore we just say mp grid and then path and what this is doing it's basically linking the path which we have created now and then our path here is empty there's nothing in there it's not going anywhere just saying like hey where do we want to go and then we say like hey link our path uh and then the id this is basically hey what kind of grid what are we using of course you can have multiple ones then we just use the grid which we're having in our setup so i just quickly copy paste that into grid then we're using our path and then we have linked the path with our grid together and then we say like hey where do we are we starting and of course here we're just using our current x and y position and then say hey where do we actually want to go then we say to put that into our target of course here once again you can go with coordinates if you just have them want to go with them in a specific direction and then it says allow diode diagonal movement here basically here this is the little illustration from them so here if you just say mp grid path then this is just saying okay if you allowed uh if you allow grit a diagonal movement then you can go diagonal if not you go uh like this kind of stair movement and this is just basically this so for example here it makes sense for us to go diagonally and that's why we say one and allow it for now still nothing is happening and therefore we just need to say like hey now we want to write on this specific path which we linked and then created because now actually we're having one and therefore we just say path start and if you watched my other videos on path and i guess you know so we need to go what kind of path are we using on a watch which one are we writing what kind of speed are we using so how fast then what we do if we uh well end up in our destination and then absolute true if this is absolutely on the path and then one thing for example what we can do also and this is of course optional you can actually draw our path on which we are walking so here draw path and needs a few parameters so here once again which path do we want to draw so the one which we're having then starting from our position and then absolute so basically once again um the thing and then for example once we started everything is set up and this is basically it alrighty so for example what you're seeing now aha you see those green lines so this is uh well the grid which has been drawn now a little bit more transparent as you can see now uh everybody is walking in the conga line and then well this is just basically it how the whole thing is here and as you can see they're just updating every two seconds and therefore you see um they're drawing a path to the last location where they want to go and of course they update it and then obstacles and stuff are not an issue and of course one thing which you see is they will cluster around and then for example they have no collision to each other and therefore this is the thing which i'm gonna address in the hotline manager series but for most games this will be more than sufficient because as you can see this works already pretty decent all right that was it that was the the the pretty good ai path finding and using a grid so basically once again setting up the grid once and then setting up and updating the path in the alarm event so we're looping this and then we get this pretty pretty decent result how to do that and of course one thing for example if you want to have a little bit more control then later on you you adapt how you want to handle the path for example if it's for example should be stopping if it's for example some changes because here um once you set up the path it will go for infinity for example if you just set it up once then it won't be stopping and therefore here this is where you take control in the ai region already without any further ado there was it from my side hopefully you enjoyed this and then you can use the best path finding which is inside the game maker studio 2 and 1.4 and so on well you can just use it and well it's easy to set up alrighty that was it from my side have a good one up indy
Info
Channel: 1up Indie
Views: 1,799
Rating: undefined out of 5
Keywords: game maker pathfinding, game maker 2 pathfinding, gamemaker studio 2 ai pathfinding, game maker motion planning, gamemaker studio motion planning, gamemaker easy pathfinding, mp potential settings, mp_grid, gamemaker mp grid, gamemaker mp grid tutorial, mp grid create, mp grid create tutorial, mp grid add, gamemaker grid tutorial
Id: gqzsBhb7ov4
Channel Id: undefined
Length: 15min 49sec (949 seconds)
Published: Fri Sep 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.