Godot Wave Shooter Tutorial #10 - New Enemies + Refining Screen Shake System

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to the way she's toriel series and we are at tutorial number 10 nice job guys he made it this far we did set up a camera shake and in the older tutorial but what happens is I don't think it looks good it works well it just doesn't look good enough and I have a simple solution to make it look better than what we have it looked before so I'll be doing that and then we'll be refactoring the enemy system just gonna allow us to make more enemies and just build upon the base enemy system really easily but let's get into it so we're gonna be going into our camera 2d script and the first thing I want to change is this zoom in intensity I think I said it to like 0.01 5 as my intensity and that was good value I found that worked well I also don't like what I did right here where I just set I snapped back the position the 3:20 about 180 cuz let's say the screen is shaking and it drifted off to a certain point on the screen it's gonna instantly snap back to that specific point and it just doesn't look as good as I wanted to so we're gonna cut this line out with ctrl X and then I'm gonna do I'm going to go up here let me add a line to scroll over enter okay I'm gonna do an else so if the screen is not shaking anymore we want to do global position equals lerp I guess I didn't have to cut it I'll just say work global position comma vector to 320 by 180 that's the position we're moving to at 30% speed so now we are interpolating our position back to the base position that we were using before so I think it's gonna look a lot better when we have it this way but we're not done yet because I have to go into the enemy script we're gonna update it and I think I found 80 as a good value at like 0.2 0.2 time k so now we can run it around there arena you can see right off the bat the screen shake system looks a lot nicer and I I like this this a lot more I don't know it just looks nicer than what we had before and you could change these values if you want to go all the way up to 120 I like 0.3 or like 0.3 seconds see how that works but I think 80 at 0.2 is gonna be one of the best values yes it just has too much extra shake because at 0.3 so if I set that back to 0.2 let's see how that works but it's kind of just a matter of fine-tuning and figuring out what values work for you yeah I like that um so refactoring the screen shake system if this was an easy way of doing it I've there's a discord user on our discord server link in the description if you're interested in joining they messaged me and they they they were showing me their screen shake system and they were using tween which tween is just like the ler but tween actually has more customizable permit parameters and they can overshoot values and have different curves so it's a bit more advanced than lerp but it does work pretty well ok so that I think that's gonna be our screen shake system rework but now let's jump into the enemy system so let's open enemy GD and open our enemy scene so a lot of our enemies are gonna be the same they're usually gonna have a lot of the same behavior when we get hit by a bullet we wanted to hit turn why we want to knock back we wanted to lose HP and we want to get stun all this so we don't want to be making enemies and copying and pasting code across because if we have to refactor the knock-back script let's say if there is a problem in the knock-back for it and we have multiple enemy duplicates we would have to change that in every single enemy script and that is that is not a good way of doing it and it's just a lot of work doing it that way so we're gonna be using so they called scene inheritance that goat uses that will inherit the same scene like this this entire same tree every enemy will have this same same tree and they can add more scenes into this tree but they'll have this same base tree before we set up scene inheritance what we're gonna do is I'm going to make a new script down here in the file system I'm gonna right-click new scripts recall this enemy core and instead of inherit to know that we're going to inherit sprite or whatever you're using for your enemy we're using sprites in this case a lot of tutorials actually use kinematic bodies but we're not using a physics detection so we're just using simple base sprites so make sure it's inheriting spray and we can hit create so now locate your enemy core script double-click it and we're going to be copying and pasting lots of these base stuff from this and script back to this enemy course script so speed velocity stun HP blood particles this can all go and our enemy core spring I'll talk a little bit about setting these properties without having to change the screen sorry I save that and now we're gonna get some errors in our enemy script because these variables no longer exist in this current script but what we can do remove this extend spray grab the enemy core script within the file system drag and drop it so now you see it says extends and then me cord Gd so it's no longer extending to its base spray class it's extending to a script that we have built and this script and it goes back and inherits from the space sprite class so we're still inheriting from a sprite but we're also inheriting from our core script right here which is allowing us to use these same variables from this core script back and our enemy now this is a really nice way of doing it because if we want to add in our variable we just add it to the script we don't have to copy and paste it if we have multiple enemy scripts so that's that's one of the great ways of setting up scene inheritance I guess this is more just like inheriting a script but it works really well I don't want to copy and paste the movement that we have right here because that the thing is that you might have a different movement system for different enemies you might have ones that I don't know - towards a player or something every enemy we might not want to use the same move script we might want and it means to - towards the player have different movement systems so simply copying and pasting this into the enemy core process script might have some problems with other enemies if you're trying to have a different movement system so the best way I see of doing this is wrist I'll cut it and we're going to put in our enemy core system and in this system we're just gonna be setting up a function where I call it basic movements towards player amaura paste this code in sing it wants the Delta variable because we don't have the same Delta variable we have from a process of it so if I wanted usually the process event has a Delta variable that you can grab and use right here problem is this function that we set up our custom function does not have adults a variable so the best way I found the this is actually sending a delta argument like that and then when we call this function will actually give it our Delta value so now the enemy can choose okay if we want some basic enemy movement that we're we are gonna be using for this enemy we can copy this function paste it right here and just give it our Delta variable and we could save that and it's grabbing this function and still moving towards the player with all of this code without having to copy and paste it because if we wanted to change our base movement system if we copy the pace of it enemy the enemy it's gonna become a problem of changing it that's why we're using this basic movement system towards the player and this function works really well for stuff like that okay know with HP you're probably wanting the same thing with the HP camera screen shake we might want to have a camera screen shake a different value between enemies we could set that up as a variable so I'm just gonna copy and paste that and so we'll cut this and we'll paste that into a process function and you could separate every single one of these into different functions but I think that kind of gets tedious because in every enemy you usually want them to die so you're probably gonna have to be like check HP basic movement and basically you're have to put in every function but if you want have different enemies that don't have the same HP system then go for using a different function but for now we're gonna be using the same movement system so we'll be using this one right here we're also not using our Delta variable right here so you can just do underscore Delta that to tell Co that we're not using the Delta variable it doesn't really matter but I find just doing underscore Delta can help improve performance okay so now we're gonna go back to our enemy script and let's see what else we want we have our hitbox area entered where we knock back we see that we do have an arbitrary knock-back value so we can also set that as a variable so we're gonna cut this and we are gonna paste this into our enemy core so you might be worried that we're copying and pasting a signal into the enemy core but since the enemy core is inherited from the enemy scripts we've already connected the hitbox entered so it should be going through the enemy core either way and we do have a problem here too on our stun timeout we said it as the original color and we can easily fix that as well we'll just paste that in to the enemy core and we'll fix all this later just untie our timeouts now we'd save all of our scripts so we basically have and then the core that holds all of our code that we had in our enemy but now the enemy is using its basic movement towards player as its own code so we could save that and let's run it and make sure everything works and we haven't broken anything and you can see it works the enemies still move towards the player they react the exact same way and that's the nice thing about scene inheritance is if it was working in the original scene it usually is gonna work in the inheritance there you go we have awesome killing enemies great stuff going let's go back to our enemy Corrin let's fix these thing arbitrary values and make them actual variables but before we do that I'm actually gonna talk about exporting a variable when we export a variable let's say let's go to let's do that on the HP right now I'll just say exports integer Bar HP equals 3 so what this basically does is export if I save the script and I am fullscreen it I go back to our player and you see there's an HP value now in our script variables category and it's saying HP equals 30 and we could set that in the editor without making any changes to the code so this is nice if you have multiple scenes and they're using the same script but you won't have different variables you don't want hard code them in you could just set them as an export variable and you can change those variables within the editor without making any changes but since we said they equal the three the default value in this category is going to equal three and we also have to specify our type which in this case is an integer that way when I hit up and down it's not gonna increase like a float it's gonna be whole numbers because if I do the float I save this now it's gonna allow me to do 3.1 when if I go back to an integer I cannot do 3 if I try to type in points it's not 3.1 it won't work it was just round down to three so that's the great thing about exporting variables is you can set these easily okay so we're going to be doing the same for our speed it's gonna be an integer because we're not going to be using values in between and yeah we'll just do export int var speed equals 75 now we can edit our speed and our HP within the editor now there's a couple more things that we have problems with our knock-back we probably want to have we probably want to have that as a variable so we can edit our knock-back so we can try to set a value for a knock-back and says next for the problem with our current knock-back system is it's using our speed variable velocity multiply speed by x Delta so if our character moves faster he's instantly gonna be able to knock back faster no matter if we change this value or not and we're gonna actually gonna fix this right now we're gonna cut this code of moving our global position with our velocity and speed and we're gonna paste that right here we're only gonna do that if the player is not equal to null and we are not stunned as soon as we're stunned global position plus equals velocity multiplied by Delta we do not want to incorporate speed in our knock-back and so that will instantly fix our knock-back system where we can set this as a value and that won't be affected by the speed now our problem is with the new knock-back system implementation we're gonna have to be using different values and six because the enemies are going to move back like six pixels wouldn't we do that so if I jump back into the game let's see this or have some enemy spawn in here really soon I'm hitting him he's not really moving back he's kind of just sitting there he is moving back just a little bit moving back like six pixels and to fix this we're going to go back into our enemy course scripts and we're gonna have to set this value a lot higher so weird him like do 60 let's see how that looks so this is knock-back at 60 still not really much you could still see that they're getting knocked back though so let's set it to like 6000 let's try 600 let's see let's see how much knocked back that will be you're saying 600 is pretty good value I was thinking this is gonna knock back a lot more that's like what we were having before so we'll set that our default knock-back value but we'll set it as a variable in the editor so we can change that as well so go back to our enemy course prett and instead of having this as an arbitrary value we're going to go back to our variables and I'm just an export integer var knock-back and I will set that the 600 by default and then I can copy this knock-back variable name and we could paste that in as our 600 but then we also have a problem with this arbitrary setting up our color value because that's only gonna work for our red color so if I try to change the color to like so let's say we set to a yellow color and then we save and run it the thing is it's gonna turn back to red as soon as we as soon as he goes out of his knock-back stage because he turns white in the asset turned back to his original color so you see how he's turning red which I mean that could be a cool enemy that resets to a different color every time you hit them just like showing a different state but for right now that's not what we are planning on doing so we can exit if we go back into our enemy core to fix this I'm gonna copy this hex code value so I can get back our enemy adds original color I'm gonna select the enemy copy and paste the hex code value that way I have him back at red so instead of sending him back to this value let's create variable to start variable current color variable called current color equals modulate that gets compiled at compile time as soon as I hit that run button and modulate isn't gonna be set up yet so we're gonna get in there oh modulate doesn't exist so on ready make sure if once everything is initialized then we set our current color to modulae and this is our modulate color so now we can copy this current color and set modulate back to current color and we can run back our arena script and let's make sure everything is working but you should see it's working the exact same as last time it's just using more code so now if I send them to yellow I'm gonna copy my hex code value before I send to yellow cuz I'm gonna make sure I don't lose this color value and I'll set it back to yellow I'm gonna save it you can run it and now I'm gonna be moving around enemies are yellow I hit him and he's still yellow his blood is pink we'll have to set it up so the blood will become the color of the your current color so I'm just paste my current modulate back but now it works with multiple colors and now we have our enemy core set up so you're probably thinking this is the exact same as what we had before but now we set it up in the way where it's expandable we still need to set the screen shake value though so let's do that first exports integer var screen shake we'll just set that to 120 by default and we'll set this screen shake value right there and you can run it and make sure everything works still and you have enemy's correct color same screen shake everything works so let's say we want to add multiple enemies now let's get into the scene inheritance cuz we don't want to keep having to sit up the same same tree with the hitbox collision shape the Sun timer and have to connect that all up I think that would be lame having to set that up each time so what we can do this we can do scene click up here in the scene do new inherited scene select your enemies awti sen and rather hit open now we have an unsaved scene so you're gonna see these nodes in the scene tree are greyed out that's because they are inherited of these values and it's saving the enemies scene right here and it has a little scene icon and this will take me back to the source scene that's inheriting from these are all being inherited from the current this current scene the enemy seems like it still edit these values like let's say i wanted to change the collision layer well I could do that to this one it just won't affect the original enemy but if I go through yet current and then me and I say okay I want the color of all the enemies to be yellow I save that I go back here and now this one's yellow now I sit back to my current value and I save now this one's back at my current value so the thing with this system is if you have the first enemy and you make changes to the first enemy it will make changes to all of them so either you inherit from this one again let's say with this one we were actually gonna be using this one as the enemy one we can just inherit back at enemy one that way we could change the color of this one so we've changed that back to yellow we could save this one you'll want to save to its own scene that's okay again hey enemy one dot T SEM it's safe and this one's still gonna be red because this one is its own kind of scene but it's just gonna be inheriting from this base scene so now we can rename this enemy base and save this one and then with enemy one I'm gonna set back to its original color value and then we can save here and that's basically that's how you can deal with setting setting up the original enemy without having to change all of the other inherited scenes but we have our speed that we have our HP we have our knock-back and we have our screen shake we can also set up our own scripts because right now we're using the old enemy script right here and I'm actually gonna rename this enemy script so we have a good understanding of what it is I'm gonna rename it to enemy enemy simple let's call it enemy simple rename and it might say another resource is loaded enemy simple and it's gonna have an extra script that's empty up here that's because we renamed it and it's just seeing the old script still so we hit closed that's just fine so now it's called enemy simple @gb and so we could set up different scripts for each enemy now we have enemy one let's actually make another inherited scene so go back to your base scene do a new inherits scene and make sure you have selected the base scene and hit open we're gonna call this enemy - let's make our second enemy and let's say we wanted to come yellow like we had before we have our yellow enemy and it's enemy - let's say the lip yellow enemies are actually a lot faster let's go like 140s or speed and we'll just set their HP like one and we could set knock back to like twice as much - 1200 and screen shake we could set quite a bit lower we could set this like 70 yeah we'll go we'll go 90 and then you hit ctrl s and you save we already made a new enemy we didn't have to change any code we just had to change couple parameters and the script variables so if we wanted to have a different movement system we can't just change the enemy's simple scripts because that would change this enemy script the enemy one because that's it using this same script so if we wanted to do a different movement so you'd have to clear the script right here I have a new one enemy we can rename it Alamo enemy - dot GV or something and then you'd go into enemy Corps you add your own function for the different movement system like basic - movement and then you call that in this new script you'd have to make a new script and you call it in the process make sure it's inheriting and you do that all there for now I'm just gonna leave it as enemy's simple thought Gd and leave that there but if you want to have different movement systems you just do it that way but the only problem is we have new enemies we're gonna have to fix our blood particles the problem is we can't have it as the same color as the current enemies because it's gonna be hard to see the enemies above it so I'll have to figure out solutions for that it should just be lowering the values but for now we'll just deal with the normal blood particles but we're gonna run into a problem it's gonna only spawn the original enemy and I mean one we want to spawn enemy one enemy two and so forth so I found an easy way of doing this will be using our same export variable system export array and in this array we are gonna be using packed scene and so a pack scene is like one of these t sen files right here like i enemy to the tsdm that's a pack scene then we're going to do variable recall this enemies and we're gonna save that so what this is gonna do is if I go to my arena no 2d it's gonna say enemies this is array size zero I click on it so it expands this and I get set size to 1 okay we want one of the means spawn or if you want two different types of enemies spawn then I can load a pack scene enemy one it will load this one to the array now I can load another one or enemy - I know what our enemy - in the array for some reason the previews don't look right enemy - should be yellow I think it has us I think it's a problem with scene inheritance but it will be yellow it's just gonna show up as red on the preview but they're still not gonna spawn the enemies but we do have a variable that has our enemies contained in it so we don't we no longer need to preload this because now we are gonna be using this one so when instancing a node we want to pick a random enemy within our array so to do this before I before I change this we're gonna have to set up a little variable up above here we call this variable enemy number it's gonna pick a number from what these scenes are because it numbers them zero two however your sizes so zero one two three four and it'll go all the way down and you can see our size is two even though only goes up to one so the zero index in our array was enemy one this one index in that right is enemy two so we can do this to randomize the enemies our spawn so enemy number equals R and range we're going to do zero because that's our start is the zero index two enemies enemies dot size minus one we can't just do round Rand's range though because it will give us values in between we want integer values we don't want float values so we'll have to do round random range and do the parenthesis around this random range no reason why we have to subtract one from our enemies size is here if I show you it says enemy size is 2 but our last index is 1 so if we subtract that our last index our enemy size will actually be 1 but it will align with our last index and we're going to be using this indexing system so if I do enemies and I put bracket enemy number so let's kind of break this down piece by piece we set up an enemy number variable we do random range we make sure we round this so it's integers so we get 0 or 1 in this case because we only have two enemies and when we're retrieving or index like right here it has to be within 0 or 1 even though our size is 2 because if we write one in our index it will retrieve this scene which is the enemy - if we write zero it will get enemy one so that's why we have to do enemy's stuff size minus one so that so aligned with our array values this is a bit confusing so I hope you guys kind of figured out how this works it's just doing array values and aligning them correctly and getting a random enemy from those index values and this will basically return the enemy that we selected from our enemy number so if I save this now I run it enemies are gonna be spawn randomly now oh we got yellow enemy shoot them knocks back quite a bit see if we gave you red enemies oh there we go if we got red enemies - think I should make the yellow enemies a bit faster you don't seem faster there and you can see it randomly selects the enemies and it all works only problems we have right now as the game is way too difficult so if I go back into our arena script I'm going to set the difficulty the wait time instead of minus equals zero point one let's just make it slowly easing I feel like it eases in too much so let's actually - wait I'm by 0.25 let's try that your point zero to five that way it slowly eases into more and more enemies we got yellow enemy they still have red blood we'll fix that next tutorial don't worry about it bonding in a bit more rapidly and I think the difficulty curve now is a lot better with having a lower value and we have enemy spawn in randomly and we have enemy inheritance so I think this is actually this is really good because now you guys can actually add a lot more content really easily within this project will fix the blood particles it's gonna have to it's gonna take a couple things with color cuz we're gonna have to make it a bit darker so you can actually differentiate the enemies from the blood and will also make the blood fade out as well so I hope you guys enjoyed this tutorial and I'll see you guys in the next one
Info
Channel: PlugWorld
Views: 3,009
Rating: undefined out of 5
Keywords: godot, game development, godot engine, godot tutorial, game dev, GDscript, godot tutorial 2d, game polish, game feel, godot 3.2, tutorial, top down, shooter, wave shooter, learn gamedev, series, godot 3
Id: qM0iQDnfJZs
Channel Id: undefined
Length: 25min 58sec (1558 seconds)
Published: Thu May 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.