New Mob Types + Animations - Tower Defense Tutorial #3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my fellow gnomes and welcome to part three of our tower defense series and this is an action-packed episode as you can see because we're introducing some new mob types we've got some animations going on and our game is starting to come to life so if you want to find out how i've done this then keep watching and i'll show you how we're going to get rid of our just boring zombie and we're going to add in some new mob so i'm going to paste these into the workspace i've got look at these i've got four new mobs well three new ones and here they are we've got our zombie we've already met we've got our noob character who is similar but i've uh have modified his humanoid and i've given him a little bit more health and i've increased his walk speed it's a bit faster then we've got this met character and he's sort of like a heavy tank so he's got a lot more health but he walks pretty slow and then we've got as our boss of course we've got teddy now teddy walks even slower he's got tons of health so he's going to take a bit of killing now all of these characters if you want to use them i've published them as a free mole so you can go and take them and you'll notice all of them they have their own animations folder inside and the walk animation now you can use whatever characters you want but make sure that you have an animations configuration folder like this and an animation called walk inside it with your animation id if you are using uh mine then the animations are all ready to go apart from the zombie and the teddy you will need to uh to publish the animation yourself because this is just my animation but you can do that easily if you see there's an anim saves folder if you click it go in with your animation editor select the rig and then you'll see the animation will load for you and all you need to do is publish to roblox and then get the id for yourself so with all that done let's move all of these mobs now grab that folder and move it into server storage and we can get rid of that old mobs folder that just contained the single zombie delete that now the cool thing is do also just add these to the game we've already done most of the ground work so i could just head into my main script here and where i was spawning three zombies well i can just spawn in three max instead so if now if i click run i should hopefully see here come three mechs and out they come moving a little bit slower how about we spawn in uh some together so we spawn three max and three zombies like oh zombie not plural zombie singular we run that we get the three mechs and then behind them the three zombies now we'll see because the zombies are a little bit faster they're actually going to catch up with the mechs and they're going to kind of push against them and obviously this is not ideal at all it's a bit of an issue really so how can we stop these collisions going on between our different mobs well in order to do this we'll stop the game we're going to use something called collision groups so if we go to the model tab on the top of our screen and we'll click collision groups it'll bring up a new window here at the moment everything in the game is under this default group and we're going to add a new one in called mob so right at the bottom just type mob hit enter new word appears and you can see by default it's going to be interacting with the default group that means it will actually collide with the base plate and everything else which we want but we don't want it to collide with other things tagged as mob so we untick that and then we're also going to add in a play group as well because we don't want our player to be able to run in front of the mobs and stop them from walking so we want to disable collisions between the player and the mob we'll untick here and i guess we might as well disable collisions between each player as well so untick there so we should just have our one column here but everything will collide with the default but they won't collide with each other so once we've created those collision groups we can actually close this window and now we need to set it up in our script so we'll head into the mob module script and just after we spawn them in here in the mob spawn function i'm going to need well first of all i'm going to need the physics service so actually at the top of our script where we like to put all our services we put local physics service and i'll make this variable equal to the physics service now we've got that we can go down here as we were before and we're going to need to set every single part within the mob to be part of this collision group because this function we want to use physics service set part collision group that takes a path and the name of the collision group which is the mob now we can't just set it to the whole model we need to set it to each individual part so to do that we're going to loop through them four i object in ipads and then we'll do new mob hold on and we'll call the get descendants method now we don't want to use get children like we've used before and the reason for that is because a child is just the top level whereas descendants is everything right children and sort of grandchildren i suppose you can think about it so if you're a bit confused by this if you look at the server storage here you'll see server storage has one child which is the mobs folder and then the mobs folder if you open that up the mobs folder has these other four children but these aren't the direct children of server storage right snow storage only has this because it's only it's one child and then all of these together are its descendants they want to ensure we get everything regardless of the hierarchy once we've done that we're going to check if the object is a the capital i capital a is a base part because we're not interested in trying to modify any meshes or anything like that we only want parts oh i didn't put an if if then new line there we go and then we can control x or v and we'll set the collision group to be that object set that object to be part of the mob group and now hopefully once we've done this and we re run the game there should be no more collisions let's see the zombie should start to there we go they're moving through the mechs and they're slowly going to make their way to the front of the queue perfect and next up we just want to add our player to the collision group because if i spawn in with my player i can still walk in front of them and obviously we don't want me pushing them out of the way they want any unfair advantages so we're going to create a we could do this in our main script but i think what we'll do is we'll just add in a new script for now so brand new script into server script service we'll just call this on player added and so what we're going to need to do here is detect whenever a player joins so we need the player's service for that local players equals game get service players and we're also going to need the physics service again so you can copy that over from the mob module script copy that paste it in and now we will say players dot and we're going to use the player added event we can tell it's an event it's got these little yellow lightning symbols next to it play added and we'll connect that event into a function and the function will give us a player who has been added new line completes that code block it's not enough to just detect when the player joins the game we also need to detect when the actual character spawns in so then we're going to use a new another event inside of this event player dot character oh account spell out added and when this event fires i'm going to connect this to another function which will give us that character so we've got one function driven event or event driven function connecting to another function so it's a function inside of a function and then we're going to have the character so at this point we can copy what we did in our mob script over here where we loop through them all so i can select this for loop control c go here ctrl v paste it in and all i need to change is where it says new mob i want to change it to character so swap that in and hope out and i need to change it from mob to the group we want which in this case is the player group so now when i play hopefully i won't be able to now collide with the other mobs let's see there we go i can move through the ball fantastic now one other thing you might have noticed is when i get close to these and i walk away there's a little bit of a glitch in the movement do you see that they sort of judder forwards and then backwards you might be able to tell that when i get close and then walk away it's subtle but it is a change that's there and the reason for that is to do with how roblox's network physics work so when i get close to an object the game assigns me network ownership of it and when i'm away it's just the server and the little gap that that creates is what creates this little sort of jitter in movement now we want it to be really smooth so we're just going to give the server network ownership all the time rather than allowing the player to have any so to do that it's actually really simple all we need to say is we're going to go into our mob spawn function and after we've set the parent to the workspace and we just put new mob dot humanoid root part which should be its primary part and we use the that network owner function and the only parameter we have to uh give is because we wanted to be the server um instead of putting a player we just put nil nice and easy and so now when we hit play hopefully we shouldn't have any of that sort of uh jittering movement hopefully it's a lot smoother there we go really smooth and if i walk out and back in again it's not going to make any difference because it's staying on the server the whole time much smoother so now we've got these different mobs what we really want to do is have some animations because it all looks a little bit boring and lifeless at the minute it would look much more exciting if these were actually animated so to do that we're going to create a local script because you want this to be on the client on the individual device rather than happening all on the server so we go to starter player scripts adding a local script we'll call this mob animations and then we're gonna detect whenever a new mob is added to the game now i think at the moment going to our mob script we are adding our new mobs we're adding them into the map actually i'm just thinking now instead of adding them into the mob it would probably make more sense to add it this mob folder inside the workspace i'm going to move this out of the grassland folder which is the name of my map into the workspace and i'm actually going to rename it to mob with an s global and it feels a little bit more consistent i like to have a bit of consistency we've got a mobs folder and server storage and a mobs folder in the workspace that makes much more sense to me and so now we'll set it to the parent to be workspace dot mobs and if we're changing that we will also need to change uh our main script won't we i s over here change it or to be workspace dot mobs so now once we've done that we can go back into our local script we'll say workspace dot mobs dot child added and we can connect it and at the very top we're gonna create a function local function animate mob and the parameter will be the object that we want to animate so we'll connect this event to that function we've just created and now we're going to need to check that the thing that's been added into the mobs folder is actually a mob so the best way to check is probably if it has a humanoid so we'll get a humanoid variable equals object and we'll do a wait for child because remember we're on the client and when something gets added in the workspace everything else inside of it has got to load so if we just did dot humanoid or find first child it might return nil whereas if we do wait for child it's going to actually wait a couple seconds for it to load it's probably only going to be a small fraction of time but that fraction of time is important to ensuring that we don't have any errors sir we type the humanoid and the next thing we want to do is check that it actually has an animations folder remember that little configuration folder i have inside of each of them uh down here called animations and then i put the animation inside of it we're gonna check that's present so that will be equal to object weight for child again and animations which is what it's called and so assuming that these are both here we can then say if if they exist if humanoid and animations folder if they're both present then we can look for the walk animation so the walk animation is going to be equal to the object and we can do another wait for child again so copy that wait for child and it's going to be called walk if you've named your animation something different make sure it's exactly the same so mine is walk with an uppercase w wait for the child walk with an uppercase w so if there's a walk animation then we can start to load that animation so the way we do this is we're going to get the animator object inside of each humanoid there should be an animator present so local animator equals humanoid i'm gonna do find first child this time find first child animator and now sometimes uh your humanoids might not contain one or if you're you've got your own rig so they don't have them you can just do this so you can say the equals to humanoid find first child animator but or if there isn't one present if this returns false then we can just create one and just create one right now instance dot new animator and then um commission and the parent which would be the humanoid now we've created one instantly in the script and now once we've got that animator then we need to load our animation object into the uh to create an animation track so warp track is the animator we load the animation which is the walk animation and then once we've loaded it all we need to do is we need to play it warp track colon play and let's just say in case there isn't a humanoid in animations folder we could do an else down here else and we could just do a quick warning down the output we can say no humanoid or animation folder for and comma just put the name of the object object.name there we go so hopefully now if i click play we should have our animations working let's have a look oh and look down here we've got a infinite yield possible on mobs.zombie wave child walk ah i see what's happening hit stop and look we tried to look for walk inside of the object itself whereas we need to look for it in the animations folder don't we we're gonna go to the animations folder and then look for the walk animation object there we go and look at our animations here come the macs here come the zombies awesome and if we want to see what else shall we see go back into our main script how about we load in some noobs as well actually right right beneath it we can spawn in some noobs we'll spawn in five of them onto the map play remember the noobs are fast characters so they should run right through the middle of all of them and quickly sprint to the front here they come okay this is looking pretty cool i'm really liking where this is going uh now for our actual game loop in general we can start to flash this out a little bit i mean i'll leave it to you guys how complex you want to make it but i'm probably going to add on a few more waves so we're going to create 10 waves and we can start to change some of the rules here okay so i've created a bunch new rules now now so we just read through these you can see what i'm doing so if it's the first two waves so if wave is less than equal to two so one or two and it's going to spawn in actually we don't want a teddy i want to have just zombies there we go i was testing out earlier just zombies and if it's less than or equal to four so wave three and four then we're gonna have zombies and noobs and that's gonna be equal to whatever the wave count is and then we're going to do that inside of a four loop look so it's going to be repeated five times so on the third wave for example it's gonna spawn in three and that will repeat five times so we're gonna end up with 15 zombies and 15 noobs and so on then for waves five six and seven we're going to introduce some mechs as well and then for waves eight and nine we're going to have mechs noobs zombies more mechs and we're going to introduce a teddy and then finally on wave 10 we're going to have one zombie we're going to spawn in a bunch of macs teddies zombies and then finally another 10 teddies so things are gonna get pretty busy around here i mean you can do whatever kind of a logic you want but i think this will do us nicely maybe we'll need to tweak it a bit as we go along i mean let's just play here see what this is looking like three zombies to start with okay wow that's a lot more units i hope whoever's got their towers set up are ready for this [Music] as wave 10 rolls around the corner here things are getting pretty wild but hopefully your tower defense game is coming along well here it's looking as lifelike as this one if you have found this helpful then please leave a like and why not even consider subscribing thank you very much for watching oh here's teddy and i'll see you in the next one goodbye [Music] you
Info
Channel: GnomeCode
Views: 13,067
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, wave attacks, wave based, animating npcs, how to animate NPCs, gnomecode tds, tower defense
Id: Wy1nCiw2p5c
Channel Id: undefined
Length: 20min 29sec (1229 seconds)
Published: Sat Dec 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.