Adding Blood Particles (Godot Top-Down Shooter Tutorial #28)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hey everyone! Been awhile since I added a video to this series, but wanted to make a few new ones to help polish the game. Hope you find it helpful!

👍︎︎ 6 👤︎︎ u/josephmbustamante 📅︎︎ Sep 21 2021 🗫︎ replies
Captions
in this video we are going to add a blood splatter effect so that whenever you shoot another unit or you get shot you'll see that you actually hit something we'll give a little bit of feedback to the player and i'll show you how to make this particle without any extra outside assets needed let's get started okay so this is what we have currently in our game and it works we have allies and enemies we can capture bases we can win and lose but it's not anything super exciting i mean it doesn't really look that good and adding a little bit of visual polish adding some particles and some sound effects can make our game go a long way and just looking better and feeling better to play so we're going to be doing that in a couple of bonus videos here the first one that we're going to be doing is just adding some particles for hit effects but before i do anything the first thing i want to do is upgrade our player's move speed because it is glacially slow right now so if i close this out we'll go into our player scene and open this up find our player script and change the speed variable to be 150. we don't want to bump it up too much but definitely want to make it go faster and we'll do the same for our ai units so we can just come to our enemy or ally they both use the same script and change their move speed to 150 and so now if we run our game we should see that we can move a little bit faster and our ally units are also moving faster so feel free to tweak this value in your own game to whatever works for you but for me i just felt like it needed a little bit of a speed up so this is going to make it a little bit easier to test too and now we're good to actually start adding some hit effects okay so before we can actually add a hit effect we need to think about where we're gonna put it there's a couple options one is that we could put it on our actors and our players so whenever they get hit we have say a bullet particle or a hit effect particle here that we just play we emit some particles and it's definitely an option but one problem we're gonna run into is that if uh if a unit gets hit multiple times in a very short amount of time the the particle system might already be emitting and not play a new blood hit effect so if you get hit with two bullets right away it might only play one effect because it hasn't reset yet and there's ways to get around that another issue is that if your an enemy dies for example then it'll cue free the whole enemy and so your blood effect will also get freed up and it won't actually finish playing if it plays at all so we can definitely put it on our units but there's going to have to be some things we do to make that work and i'm not sure it's it's going to be worth the effort another option is we can put it on our bullet so whenever a bullet hits something it spawns a blood effect or it has a child blood effect particle we're going to run into some similar issues here is with our units because again we're going to cue free the bullet and once the bullet gets freed then the blood effect is not going to actually play and again there are ways around that but i think what we want to do to get around those and to provide some even better optimizations about how we do blood particles is to actually add an impact manager that's going to spawn a new bullet impact scene whenever a bullet hits something so in order to do that and this will make a little bit more sense as we go we're going to add a new manager to our main scene so like we've done multiple times before i'm just going to add a new node to d and i'm going to call this impact manager now our impact manager is going to be spawning or instantiating really new instances of a particle system so it's going to be something visible to the player so we want to make sure we put it in the right spot on our scene tree um right now we have our units that are getting uh they're being children of the map ai i believe i could be incorrect but either way we want it to appear above other things that we have in our game so i'm just going to drag it above everything else so it'll be farther down in our scene tree from our ground from our walls from our units et cetera so won't we won't have to worry about it getting drawn underneath anything okay so we have an impact manager let's actually create our bullet impact so i'm going to hit command a to add a child and i'm going to just look for particles and you can do cpu particles or particles 2d if you're not familiar with particles at all you've never used them in godot maybe you're a little intimidated by them don't worry we're going to cover everything you need to know if you want a more in-depth breakdown of how to use particles in 2d i've made a video that will show you all the basics of particles that'll go through every single property that you can change and it'll totally demystify them for you and help you feel comfortable using them so i'll have the link to that video up in the top right make sure to go watch that if you're not familiar but for me right now we'll just use a particles 2d again you can do whatever you want but let's use particles2d and i'm going to call this bullet impact and so this bullet impact is going to be the particle system that appears and plays every single time someone gets hit by a bullet in this game so in order to do this you'll see again i'm not going to go through all the different properties here you should definitely go watch that video that i made but i will go through the ones we're going to use so most importantly is that you need to create a new process material a particle's material where we're going to actually set our particle settings if you're using cpu particles you won't actually see the separate process material category you'll just have a material category so either way though you can have a lot of the same options and so now that we have this you'll actually see we have particles that are dropping down right here if you zoom in they're super tiny right now so we're going to need to adjust some things first let's go down to scale to adjust the scale of our particles let's bump this up a ton let's say 10 and so you'll see that's a much bigger effect that we have right now um another thing just to make them stop going down like this let's change our direction to be one in the x or whoops sorry let's start with gravity change gratitude to be zero we don't want these to be affected by gravity there's no gravity in our game so we'll just keep that at zero and now we'll have a direction but we we need to actually give them some velocity to see them going anywhere so we'll give them a velocity of say 200 okay and so you see that it's now our particles are going with an initial velocity of 200 to the right because we set the direction to be in the positive x direction so this will be good for now but this is kind of lame right we need something a little bit more dynamic so what we can do is we've got this initial velocity let's actually bump it up a little bit to say 400. now we're going really fast um let's also come up to time i think we want our lifetime to be pretty short for these let's say 0.3 i i think that's about right so we'll have a velocity of say 400 but we need to slow these particles down right they can't go this speed their entire lifetime so in order to do that we can either use a negative acceleration or we can use damping i prefer damping for the effect it has for something like this as opposed to a negative acceleration okay so let's try and set a damping also of 400. so if i try doing that it doesn't really have much of an effect if we bump our velocity back down to say 200 that's a little bit better so it starts off strong and then it slows down a little bit so i think that's good we can bump our damping up just even a little bit more something like 500 and this has a nice effect it kind of sprays out and then stops and another thing that we can do now is actually add some color so this will start making it look a little bit more how we want so if you come down to color here you'll see that you can set an initial color or we can set a color ramp which is actually what we want to do here because we want the color to change a little bit over time so if we go to color ramp and hit new gradient texture then click on this gradient texture we can create a new gradient it's a lot of clicks just to make one thing but here we go and on the left you'll see these little boxes you can click these are colors in the gradient and on the left this is where the gradient starts so when when this comes when this particle starts playing we want it to be kind of a bright red this is like a blood particle something maybe in here again you can adjust and play with this as you want and then at the end we want it to be a little bit darker and not only darker we probably want it to have some transparency so it kind of fades out so the the player doesn't really notice that it just disappears all of a sudden so if we add a little bit of transparency you'll see that it's kind of a gentle fade out a little bit more let's actually bump the transparency all the way down and what you'll notice is that it's fading out which is nice but the problem is that it immediately because this is a gradient it immediately starts picking up some transparency right away so as soon as the particles emit they start becoming transparent and we don't really want that so what you can do in a gradient is actually add a new color along the way by just clicking anywhere on the gradient where a color doesn't already exist so if i click around here about two-thirds of the way down where there isn't a box you'll see we've got a new box that i can click on and edit and i'm actually going to bump the alpha all the way back up so that it only starts gaining transparency about two-thirds of the way into a particle's life cycle and already we can see here that this is a little bit darker i think than i want so we'll lighten it up just a little bit it kind of has the effect of appearing to get more dark um just by gaining some transparency so you don't actually need to darken it that much i don't think again you play with this um play with this this gradient on your own to make a particle effect that looks good for you i might actually take away the ending transparency a little bit just so that it's not totally transparent but either way so it's not perfect it could definitely use some work but we've got a bit of a blood effect which is very nice that we're actually starting to see um see a blood particle that comes out so we've got something we've got a particle system it's emitting it's got color but we can make this even more dynamic by actually adjusting the scale over time so we set a scale of 10 for the the particles so it's going to multiply these little square default particles and go it's going to multiply them by 10 their size but we can actually adjust it a little bit more to make that scale dynamic over time and in order to do that we'll use a scale curve by just coming to the scale section creating a new scale curve and then when we click on this curve if you've never used a curve it could be a little it can be a little intimidating at first but really it's just points on a curve that you're adjusting and so this is just relative so this is at the start of the particle's life cycle and this is the end and then everything in between is adjusted relative to how long that life cycle is and so i think kind of what we want to make it dynamic is maybe have our particles start a little less than their full scale and then i can right click to add a point on the graph and make them get bigger so they kind of explode out and then get smaller over time and all of a sudden all of a sudden you see that that's adding even more dynamicism and you may not like that effect again you can do whatever you want but i'm just trying to showcase some ways to make your particles a little bit more dynamic okay i think this scale curve isn't perfect but it's good enough for now it makes the fading out look a little bit better and um you know i wonder if i can even bump this velocity down a little bit and this is this is what it's going to be like for you too a little bit of trial and error finding what looks good i think i think that looks good actually bumping the velocity down so it just kind of spills out and then fades away one other thing i really like to do for something that's kind of exploding or it has a lot of initial velocity is to add an angular velocity and this is rotational velocity so this is going to make our particles rotate so if we add say 100 you'll see that our particles rotate as they come out now we don't want them to all rotate at the same speed in the same way so we want to add some randomness here all of these randomness properties are zero to one they're a float percentage basically so if we do 0.2 we're saying there's a 20 randomness in the angular velocity it could have so i don't know how the math exactly plays out but i think that means since we're at 100 it could be either 80 to 120 angular velocity so there'll just be a little bit of a difference in the velocity that they do have but you can already see there's a little bit more movement these particles are a little bit more dynamic than they were before so this is really good i think it's very simple it's very basic but we didn't have to add we didn't have to create any of our own our assets and you know it kind of shows but this is really easy to do even if you've never used particles before and it's super easy to add your own material your own texture you can just add them right down here and godot will work with that so i think we're almost there the only other thing i want to do is maybe let's try bumping up the actual amount of particles that emit at a given time that might be too much but we'll see um i bumped it up from eight to sixteen eight is the default another thing i wanna do is adjust the explosiveness this is basically saying how like for all if there's eight particles that emit at a time how how grouped together are they do they come out over a certain span or do they all come out at the same time an explosiveness of one means that all the particles will come out at the same time so if i set this explosiveness to one you see how it's just like an entire they all just come out at the same time if we do 0.5 you'll see that they kind of come out over half the time so there's there's kind of a wave effect to it i think for something like blood you don't want it you want to you want to have it pretty close to one but not all the way so if i try something like 0.6 you'll see that it mostly comes out at the same time but there's a lit there's enough of a variance that it makes it look a little real and i'll add a randomness of 0.2 and this will affect a lot of these time properties just again we're just adding more and more dynamicism to our particles okay the last thing we want to do now that we've seen our particles and seen what they look like is to add or to make these one shot that means that every time the particles are set to emit they'll only play one time so we have to click it or programmatically toggle it each time we want to play i'm also as i'm doing this i'm looking at these and i think we want them to be slightly bigger i mean that's going to be a pretty small effect there so let's just come back real quick to our scale and let me bump it up or move this to not be one shot for now just so we can see it in action let's change our scale to be 15 and see what that does i think that's going to look a little bit better what we can do now is just adjust our velocity to match and we can maybe make our damping a little bit higher just because we're shooting out a bit more now but i think that's good and again once we actually see this in game we'll continue to adjust as next necessary i'm also going to change our spread direction or make it a little bit less spread so they come out in a little bit tighter of a line so i might try 30 and you'll see that they're it's a little bit tighter uh the angle that it comes out okay so that's enough tweaking of our particles again move this back to be one shot i think this is good enough for now and now that we've got this bullet impact seen here what i'm going to do is right click on it and then i'm going to save branches scene as a bullet impact and we'll put this in weapons since that's where our bullet is so we'll save our bullet impact scene and then i'm actually going to get rid of it delete it from our tree and i'm going to add an impact manager script we'll just keep it in the main directory for now there's definitely some reorganizing we can do in here but uh you know save that for another day i feel like we always say that but you know save it for another day and now that we've got our impact manager script we can actually add the code to instance our bullet impact every time our bullet actually hits something okay so before we actually start adding the code to our impact manager we need a way to communicate to our impact manager that a bullets actually hit so in order to do that we're going to come into our global signals script and we're going to add a bullet impacted script just like we have for fired so signal oops signal and this is going to so signal and then bullet impacted and we're going to kind of have to figure out by working through this what we actually need but i'll just give you a spoiler it's going to be the position so when a bullet hits something we need to know where it hit and which direction it's going and so that we can correctly rotate our impact so the blood comes out at the angle that a player would expect so we'll need the position of the impact and the direction that the bullet is going when the impact happens and so we need to actually emit this signal now from our bullet when we impact something and so if we go into our bullet script you'll see we've already got this on bullet body entered function which is perfect it's exactly what we need and we're already detecting when we've hit another unit now there we could also do impacts for scenery for the environment and that's definitely a good thing to do we won't quite get there in this video but you could make your own uh you could differentiate a blood impact versus a environment impact and have different kind of particles and then spawn them depending so we know that if we get in this if statement here if the if our bullet has hit something that has a handle hit method then we know that we've hit a unit and we also have a check here to only do damage if that unit is of the a different team than the bullet i think we still want to play our blood impact scene even if we hit the same team so the player will at least see that there you know they hit something even if it's not going to do damage so what we're going to do here is say global signals and we'll do emit signal and you'll see we'll have our bullet impacted script and we remember that we need to pass in the bullet's position and we need to pass in the bolts direction thankfully we have a global position variable that we can use and you'll see if we go back up to our set direction you might have to you know remember this it might have been a while but you'll see that we have a direction vector that we're storing the bullet's direction so this is perfect we can just pass in direction okay amazing so we're emitting our signal when we need to be we're sending in our position and our direction now we're ready to actually handle this from our impact manager script so let me get rid of all this boilerplate and someone commented and asked why i didn't remove the boilerplate because there is a way to remove that on all of your scripts so you don't have to do it manually it'll just it won't be there when you populate a script and it's a really good question and i'm sorry i haven't i just kind of i don't know it takes two seconds and just never really got around to it but definitely something to do if it annoys you for me it's just kind of you know it's like a comforting habit i guess so we've all got our routines um but anyway we're ready to receive this signal now on our impact manager so if i do global signals and i do connect we can connect to our bull impacted signal here and we'll say self because we want to handle it here and we'll just say handle bullet impacted you guessed it i'm going to copy this function name so that we can use it right down here and just say function handleball impacted and remember this is going to take the same parameters that we have coming in from our signal which is going to be position this will be a vector 2 and direction because remember we're storing our direction also as a unit vector so now within this we're ready to actually do our or just start spawning our bullets so there's four things we need to do we need to spawn our bullet impact we need to put it in the right position in the right direction we need to set it to emit and then we need to clean it up or free it when it's done so those four things we're going to do in that order so the first thing we need to do is actually get a reference to our bullet impact scene so that we can spawn it so i'm going to do const and i'll say bullet impact and remember whenever we're doing something that is unchanging it's a constant reference we the right syntax the best way or the best style is to keep it capitalized so that even if you weren't in the script even if you didn't know what it was whenever you see something that's in all caps you can assume it's unchanging it's a constant value and this is a constant value because we're going to reference r we're going to preload and reference our bullet impact script which is at res and remember if we go over to our scene or our directory here it's in weapons and then bulletin pack.t scene so do weapons and then slash and then bullet impact.tc there we go so we have a constant reference to our bullet impact our packed scene and what we're going to do here is just spawn it in so we'll say var impact so that we can store our new instant scene and we'll say bullet impact dot instance just like that and now we can add it as a child of our impact manager so i've got this and i will add impact and there you go just like that we are creating a new bull impact and adding it to our scene so that's step one step two is actually like we said setting the position and the direction this is also very easy and the nice thing is that because this is a one-shot particle it's going to be set its emitting property will be set as false by default so we can add it to the scene and move it around and it's totally fine it won't actually play a particle until we tell it explicitly to emit so we can add it to the scene and then i'll say impact.globalposition equals position and we'll say impact dot rotation we'll do global rotation i don't know if that matters we might have to tweak this sometimes i get a little mixed up with the direction stuff we'll say direction and remember because direction is a vector we have to get the angle value of it so now we're setting the position and the rotation of our impact to match what the bullet's hitting this might be uh 180 degrees the wrong way we might have to do like negative angle or negative rotation we'll figure that out from there um but we should have step one and two done now the third thing like we said is to actually set it to be emitting so once our impact is facing the right direction we can say impact dot emitting whoops emitting to true now the fourth thing is to clean it up and we're gonna actually have to change this line of code because right now we don't have a way to know when our particles are done emitting and so what we need to do is actually go to our bullet impact scene and you'll see that there's this emitting property here just like we'd expect well let me try and get to the scene so you know if i check it we emit and then it turns off when it's done but we don't actually have a way to know when this is over there's no signal attached to particles right now unfortunately that'll tell us it's done emitting so we've got to add some of this functionality manually which is totally okay so we're going to add in our bullet impact scene just a timer and this time we'll call um you can call whatever actually we'll just leave it as timer and we'll you can just set it to be one shot auto start this is all fine and what we're going to do is add at a script to our bullet impact and basically what we want to do is when this enters the scene tree we want to set our timer so i'll say i'm ready var timer equals timer and what we're going to do is say timer dot wait time so we'll set the time of the timer the wait time to be our particle's lifetime and if you mouse over lifetime here you'll see that in order to get the lifetime property it's just lifetime so we can set timer.wait time equal to lifetime and just like that our timer is going to match the timing of our actual particle time and we can add just to make sure everything all the particles are completed we can add a 0.01 second buffer you can do whatever you want you know you'll kind of feel it out but anyway we'll do this and then we'll say timer dot start and remember our timer we'll turn off auto start actually our timer is one shot so it's only going to do this once and then what we can do is actually connect uh to our timeout signal on the timer so now that we have this and we're connected to the oh let me uh let me just add that line there that's going to bug me now that we're connected to our timer's timeout signal we can q free whenever we're done so we can just say cue free and that way our impact manager is not going to actually have to be responsible for um for freeing or keeping track of all of its impacts they're going to free themselves now the problem is that we've been doing all this on ready so whenever the scene or the bullet impact enters the scene tree the timer is going to start but we're not actually do setting it to emit right when it enters the scene tree so a better way to do this actually is to probably say to create a new function in our bullet impact and we'll just call this function start emitting and it's really gonna do exactly what we've been doing up here we're just gonna i'm gonna cut that and paste it and just start emitting and we'll say emitting equals true okay and we can get rid of our ready function so we're not actually going to use ready we're going to manually have to start emitting our particles and then so in our impact manager we'll change this impact.emitting line to call impact start emitting and start emitting is going to handle everything for us because start emitting we'll start our timer and then when our timer finishes the bullet impact itself is going to be connected to it and it'll free everything up so we don't have to worry about anything at all and if later on we change our time for our particles that's all right because we're doing our timers are the wait time of our timer is set relative to the lifetime of our particles this will just work totally fine with whatever we end up setting and so now all of a sudden we've got all four things working we are creating our bullet impact instance and adding it to the tree we're setting it at the right position rotation we are emitting and then we're cleaning it up afterward so we've got pretty much everything we need to start trying this in our game and to see how it looks so let's do that now so if we move around and i start shooting you'll see our bullet impacts now this doesn't look awesome you know it's it's definitely not there it doesn't really fit the style of our game but it's a start more than anything it's there and it gives some feedback to the player that there's an impact now you'll notice it's kind of weird because the the bullet impact currently spawns where the bullet hits but i think it'd be better if it spawned in the in the actual center of the player so wherever whatever unit gets hit if the bullet the impact spawns um at a constant or consistent part at the actual in the player's center so let's try that and see if that helps so if we come into our bullet you'll see right now that we're passing in the global position of our bullet on an impact but if we instead try doing body.global position so let's do body global position let's see if that makes it any better so if we play and i start shooting you'll see that all of a sudden now wherever our bullets hit it's kind of sending something out in a consistent spot on our player which i think looks a little bit better again you can kind of tweak in your own game i definitely i want to tweak this bullet effect so it just matches our style of game a little bit more but overall i'm pretty happy with this so there you have it in this video we learned how to create a blood splatter effect and how to apply it to our game so that there's some feedback when you or another unit gets hit or hits something if you enjoy this video a like and subscribe to support the channel is always appreciated and helps it keep growing if you do find my work helpful donating a coffee and buy me a coffee is always appreciated and helps me continue to make great videos and we'd love to have you in our community discord if you've got any questions about the videos you can ask them there thanks so much for watching everyone i'll see you in the next video
Info
Channel: jmbiv
Views: 1,002
Rating: undefined out of 5
Keywords: godot, godot engine, godot tutorial, godot 2d, how to make a game in godot, game development, game development tutorial, game development for beginners, godot for beginners, game dev, indie game dev, indie game development, hobby game development, gamedev, godot game engine, jmbiv, godot 3.3, godot 3.3 tutorial, godot top down shooter, godot top down, godot top down tutorial, godot 2d tutorial, godot shooter, godot blood, godot blood splatter, godot particles
Id: URtiyJv_yWI
Channel Id: undefined
Length: 28min 43sec (1723 seconds)
Published: Tue Sep 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.