Godot Top-down Shooter Tutorial - Part 5 (Cooldown and Muzzle Flash)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome to part five of the top down shooter tutorial and Godot my name is Joe and in this video we're gonna cover adding an attack cooldown creating a muzzle flash and how to use godot's animation player let's get started so the first thing that we want to do today is to add an attack cooldown to our player so right now if I go to our player script you'll see in our shoot method that basically whenever we click we're just gonna call this and we're just gonna shoot a bullet which isn't what we want so we're gonna add a timer to actually handle our cooldown for us so the first thing we want to do is select our player scene come up here and add a timer and I'm gonna call this attack cooldown just to be descriptive I won't change any of the settings yet but let's go into our script and get a reference to this so I had another unready variable of our attack okay great and now what we can do is whenever we shoot or get into the shoot method we can actually check the value of that timer you know is it going right now is it active or is our cooldown off so the way we actually check that is by saying if attacked cool down that is stopped and so this function returns a boolean variable that will be true whenever the timer is not running so we're gonna pretty much manage our timer manually like we're gonna stop it and end it manually for the most part so if our attack cooldown is stopped basically like we can attack then we're gonna do all the things that we're doing in here so I'm just gonna move this up and I'm gonna indent that and get rid of that and then I'll do else and we'll just pass for now and so whenever we attack we need to start our attack cooldown again something to call a tech cooldown s start and then basically what's gonna happen is if it stopped which it will be at the beginning because we won't set it to be auto start we will shoot and then we'll start it and then if we try and shoot again this will be false so we won't do anything I can actually really just get rid of this else statement right now and then when we do shoot we'll start our timer again so this will prevent us from attacking until our cooldown is and what we're gonna need to do just to make this work is set this to be one shot so it won't just continuously start and stop on its own and the other thing is that I think one second is gonna be a little bit long but let's give this a test so now if I'm clicking as fast as I can you can see I can only fire every second which is great but it does feel a little bit long let's bump it down just a little bit let's try 0.7 so you can do tenths or hundredths of a second this is a flow it's not actually an integer so feel free to set it to you know whatever number feels good so it's still kind of slow it feels like but it is you know I guess it looks like a pistol so this this feels pretty good for now it's a little bit faster and I think we've got a good value for our timer so now that we have the cooldown we want to add muzzle flash to our weapon and so in order to do that I'm gonna come back to our player scene here I'm gonna add another sprite and it's just be a regular sprite and I'm gonna call this muzzle flash just to differentiate it from our other sprite that we have there and then I'm going to add a texture to this so if I come down to the top down tanks asset pack that we have over here I'm gonna drag over the only objects image this and then I'm gonna do the same thing we've previously done by enabling a region I open up the texture region box here and we're gonna select the alright this is the one I'm looking for so this yellow muzzle flash here and I'm just gonna drag right around it it looks like we're losing let me drop down our step just a little bit so I can get the edge a whoops I did that the wrong way you need to do it for the Y okay perfect so now we've got the muzzle flash exactly as we need it I'm gonna bump our step back up and so now what I need to do is position our muzzle flash near the end of our gun right because this is gonna be coming out of our gun when we fire so we want it right here I'm gonna need to rotate this as well so I can go to our transform I think negative 90 yeah there we go let me drag it up here I pretty much just want to get it I think this is fine let's do this I'm gonna actually turn off our grid snap for just a second because we don't really care if it's perfect but I think that will be good I meant turn that back on perfect so now we have a muzzle flash sprite here and what we want to do is two things one we want to only enable it or show it when we fired and two we want to give it some animation to make it look better and I'm gonna show you how you can use godot's animation player to give even static images some animation just to add a little bit better feel so even if you don't have extra frames or other images to use animations with you can still do some tricks with godot's animation editor that'll help it feel better so the first thing we're gonna do here is add an animation player node to our scene and right now I want it to be a child of the player not the muzzle flash itself so I'm just gonna drag it over here I will probably refactor this a little bit eventually but for now this will be perfectly fine and I'm gonna add a new animation here to our animation player and I'm gonna call it as a little flash so we'll just do that and so there's a couple things I need to add one I'm gonna make our muzzle flash hidden by default because we don't want to see it until we've fired and then I'm gonna add a property track so Godot is an animation player is super powerful it is a really awesome tool that you can use for a wide variety of things all these do different you know you can animate different things typically you're gonna spend most your time using a property and what that does is it lets you affect a value like any property on any other node in your scene tree so we're gonna add a property track and we're gonna find our muzzle flash and hit okay because we want to edit a property on our muzzle flash and the property we're gonna edit will be visible and so we're gonna do two things this this UI is a little bit confusing if you've never used it before but basically these are all your tracks they'll be listed here this is how long your animations running for anything that is lighter gray is how long it'll actually go for and then these are out of bounds and you can change that value by editing this little time thing here so we see that our animation is set to run for one second right now and that's mirrored here so we at one second we lose the coloration we really want this to run for about 0.2 seconds it's gonna be super quick and then you can also zoom in or out here so we'll zoom in a little bit because we're only dealing with two tenths of a second nope not that much and what we're gonna do is add two keys one to make the muzzle flash visible and another to make it not visible so I'm gonna right click and hit insert key right at zero and I'm gonna do the same thing and hit insert key right here and at the beginning we want this value to be true because we want it to be visible and then at the end false because we want it to be hidden and so now if I run it you'll see that our muzzle flash appears and then disappears for two seconds or for two tenths of a second which is great so this in itself is pretty good but what if we were able to add just a little bit more feel a little bit more life to it so we can actually do that by adding another property track here and I'm just gonna set it to modify our muzzle flashes scale so let me hit this and we're gonna have a key right at the start that'll just be though 1 or let's set this to 1 and 1 so it'll just be the default setting and then we're gonna add a key at our end which is gonna contract the width a little bit and set it to half of the width but also make it a little bit longer so it'll really kind of simulate you know the flash and the smoke kind of dissipating and expanding and now if I run it you'll see that we have a little bit of animation that looks better I think you could still look even better I think that animation is actually a little bit long so what if we tried cutting it in half two point one and now tried running it oh whoops I need to move these back so these are gonna now be at our new and position which is one tenth of a second yeah I think that looks a lot better I almost wonder like what if we did this is crazy but what if we again I need to move it don't mind me oh and I actually can't because our snap settings are wrong so a nice thing that Google provides is you can snap your keys to specific second and so since we're on a point zero five second animation we need to set our snap to be point zero five so we can actually move to it and now I can set these here and let's try running that I think that's better honestly like with a muzzle flash it is such a quick thing like you just want it to be there and be gone and I think it makes the expansion look better where our scaling looked better because of how quick it is so I think this is awesome I think this is exactly what we want to do so there's one last thing that we want to do as part of this and it's actually an enabler muzzle flash and so if I come into our script one thing I'm going to need to do first is grab a reference to our animation player so just like before I'll do a 90 bar animation player and make sure play and then I'm going to come down to our shoot and what I'm gonna do is whenever we shoot I'm just gonna play that animation somebody do an animation play oops I think I forgot player good to shorten it to animation but I'll just do this for now and we'll do start whoops play is actually the method and then you'll see it'll autofill the name of our animation so now that will do this or now we have this every time we shoot we'll play this animation and because our animation automatically at the end sets it to not be visible this should just be everything that we need and now you see it I want to shoot we get a nice muzzle flash and look at that look how good that looks and it's so simple we didn't even need more than one image so this turned out great thanks so much for watching everyone make sure to subscribe so you don't miss any new tutorials that come out and I'll see you in the next video [Music]
Info
Channel: jmbiv
Views: 5,377
Rating: undefined out of 5
Keywords: godot, godot engine, godot 3.2, godot tutorial, godot top-down, godot 2d, top-down shooter, how to make a game in godot, game development, game development tutorial, game development for beginners, godot for beginners, how to make a top down game in godot, how to make a top down shooting game in godot, game dev, indie game dev, indie game development, how to make video games, how to godot, hobby game development, gamedev, godot game engine
Id: nnMu8s8RlYM
Channel Id: undefined
Length: 10min 52sec (652 seconds)
Published: Wed May 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.