How to make a Tower Defense Game - #1 Path Navigation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so you want to make a tower defense based game well hello my fellow gnomes you have come to the right place let's get straight into it okay so the first thing we're going to do is we're just going to create a little basic pathway for our enemies to move down so starting in a blank base plate and we're just going to add in a part there we go that will do us our basic course and that all we need is a monster to walk down it so you can use anything really but uh i'm just going to go open the toolbox and i'm probably just going to go and grab a zombie the classic monster and we'll select this one here um it's got the the approved badge here we can see it's made by roblox himself so add this one in the drooling zombie we get a message it includes some scripts pretty a new feature there we don't mind about that press ok we don't actually want any of the script inside of it so if we open it up you can see it's got animate script and so on we can delete that uh we can delete this audio clip this script spillable gui these configurations and modules delete both of them um but if we look inside animations there's this thing called arms we do want to keep that that's actually the walk animation so we'll just rename this to walk but uh we can delete the attack animation but we'll keep this walk one for now uh these ones they like look like animations but these are actually uh mesh parts so don't delete them because if you delete them you end up with a rather blocky looking character so don't do that so now we've got this little guy here well we want to move him from the start of the level here and we're going to want to move him down to the end of the map which is all the way over here so what we could do is we could add in some kind of r like this we could make this like a waypoint and then we could we'll name this one and and then inside of a script well we could just add one straight into the zombie script obviously we need to get the zombie so local zombie in this case was the script dot parent and then we need the humanoid so zombie dot humanoid and we could just say move to workspace dot and dot position but if we do that if we run it what's going to happen is it's just going to head in a straight line right to the destination that is obviously not what we want we want him to go around the path so how can we get him to do that well there's a few ways we could use something called pathfinding service but then what we need to do is you'd have to put up a load of invisible walls like this and that's gonna take quite a bit of work to build all these invisible walls right it takes time um a kind of quick and easy way we could do is because it's a fixed path it's never going to change we can actually just provide a series of waypoints ourselves that would provide this one at the end well if we just add one each turn then it can let him know where to go now before we do that i'm actually gonna get all these path pieces and put them into a folder okay i'm gonna create a new folder inside workspace we'll just name this ah and then we're gonna create another one duplicate it and we'll call this one uh waypoints so we move the end into the waypoints folder and move all of these parts make sure they're anchored and drag them into the path folder okay so just keeping things a bit organized as we go and so with our waypoint instead of just having this one named end what we're actually going to do is going to move it back to the start again and this is the first turn he's got to do and to keep track of all of these waypoints we're actually just going to number them okay so as soon as it's the first one we'll just give this a name of one duplicate it move it along and this one will be the second turn we'll just name this two i'm going to repeat this one this process so this will be three until we've done every point along the map okay so we've now got 12 waypoints all spaced out every turn along the way obviously it's a bit of a hacky solution but it does mean as soon as you're only going to have a fairly short fixed path that you can keep track of very nicely i'm going to select all these parts make sure they're anchored again disable collisions because we don't want the zombie to be bumpy into them and while here or maybe just make them sort of semi-transparent like so now what we're going to do is we're going to loop through all of these waypoints and tell our zombie here to move to each one so select our zombie again open up the script and instead of doing it like this we need to get the waypoints first of all so local waypoints equals workspace dot waypoints and then we're gonna need a loop so we'll use something called a for loop so for i equals one well in fact we could say for waypoint equals one and then the number we want the loop to go up to which will be the total amount of waypoints there are so we can say waypoints get children this will get us a table of everything inside of it and then we just want to count how many items are inside the table so we just can use a hash so for waypoint equals one and the total do and then we create this four loop block and we're going to want to move the humanoid move the zombies humanoid to instead of just saying a fixed workspace.end we want to get the waypoints and then what we do is inside brackets square brackets we designate which one we want to move it to in this case it is the waypoint variable this local variable we've created so on the first leap through it'll equal one and we're saying go to the waypoints folder and find waypoint number one which is going to be this one right here on the second loop through when it comes back around again it's gonna increase it by two increment it and it's gonna be equal to two then so then it'll go to waypoint number two and it'll increment up to by one each time so then three four five six seven until it gets till 12 which is our final waypoint now we want to make sure he reaches each one before he tries to walk to the next one so we'll say zombie dot humanoid dot move to finished and we'll just add in a colon weight i'm sure he waits each time so now we've got our zombie controller script sorted let's run that and see if we can get him moving we give it a run and oh we've got a problem there because i've just put the uh oh yeah you can see my arrow down in the output i've just specified the part whereas move 2 needs to specify a position so i put dot position and there we go fix it that's why i should always have the output open while you're scripting we try that again and there we go he moves to the first waypoint and then straight on to the second waypoint and he'll keep going until he reaches the very end and there he goes and he finishes the loop so now we've got our zombie moving along the course but we've still got a lot to do next so join me for the next video that we can actually get some wave-based attacks going thank you very much for watching and i'll see you in the next one goodbye [Music] you
Info
Channel: GnomeCode
Views: 1,931,775
Rating: undefined out of 5
Keywords: roblox, tutorial, gnomecode, gnome, roblox development, lua, programming, scripting, programmer, how to script, learn to script, how to make a game, game dev, roblox game dev, roblox game development, roblox studio, tower defence, roblox tower defence, roblox tower defense, make a game like tds, roblox tds, how to make, tower defenders, npc walk along a path
Id: DanjB0cTfw0
Channel Id: undefined
Length: 8min 16sec (496 seconds)
Published: Tue Dec 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.