Godot 3.0 - Know Your Nodes: Particles2D

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to know your nodes where we pick an individual node in Godot and talk about how it's used this time we're looking at Godot 3.0 is particles 2d node which you can use to make all sorts of particle based visual effects on the screen are a few examples that we'll be looking at later in the video if you're new to Godot hopefully this will help you get started with particles and if you're familiar with go 2.1 you're gonna see that things are working quite a bit differently in 3.0 alright let's get started so we're starting with this torch image it's just a sprite and we've added a particles 2d node to it and the first thing you'll notice is you get a warning and that warning is telling you that a material needs to be assigned and so we're going to do that go to process material and you have two choices here you can use a shader material which means you're going to write shader code to handle the to handle the particles or you can use a particles material and that's what we're actually going to use and now you can see actually we have some basic white square particles being generated and they're falling down from the spot so what do we want to do well one thing we want to do is move this so that we're gonna want it to look like it's coming from inside the torch not outside it so we're gonna Center that over that and in the visibility section we're gonna check show behind parent because I want the particles to look like they're coming from inside the torch not on top of it okay we're emitting we're gonna take the time and I'm gonna increase that to two seconds on the lifetime and I think we are done there so now we need to go into this particles material and this is where all of your crazy number of settings are for all the different things you can have your particles do and we're gonna change a few things here starting with gravity I want these things to be going upwards not downwards and so I could go in and I could change the gravity which right now is set to positive in the y-direction but I'm going to set that to zero so we're gonna do this a little bit differently than the gravity is gonna make these move so we're gonna turn that off now we want to look at the emission shape here the mission shape is where the particles initially spawn and by default it's set to point so they're all going to spawn at the same point but we're gonna spread that out and we're gonna use a box and in here we're gonna set what the extents of the box are going to be and so we want to spread them out a little bit in X remember this is extents so it's five in either direction so it'll be a total of ten in width and then the Y we're gonna do about 18 so now these guys are spawning and all sorts of little places inside this box okay but our initial velocity which is right here is very small so if we were to increase that a bit let's try 25 you're gonna see that they're all flying out to the right but sort of spread out and part of that is because spread is set to 45 degrees so let's make that zero and now they're gonna be going in a straight line from wherever they spawn but they're going to the right and initial velocity is just a scalar value we can't set a direction so the way you have to solve that is back on your particles 2d you want to rotate it so let's rotate that - 90 degrees now they're spawning and going upwards so let's increase that velocity to 50 fire should be fairly quick and then we're going to talk about scale this is the size that you want the particles to be so if we increase that to say 25 we get much bigger colored squares for our particles but you can also use a scale curve to change the scale of the particle over its lifetime so if we click new curve texture and then click on that new curve we've made we get a new panel opened up here at the bottom where we can alter the so let's say we wanted to start it around there and then scale down to say just under halfway so this goes between zero and one it's a multiplier to that scale property you have back to properties we can look at the angle this is what angle they'll be rotated out we're going to make that 45 so they're more like diamond shapes instead of squares and then we're going to talk about speeding these things up so there's they're starting out at a certain speed but we want them to sort of accelerate as they're going upwards and we can do that with the linear acceleration so that's going to accelerate in whatever direction we're going so if we make that about 25 you'll see now we are accelerating upward as we go and you can see them moving upward that's good and let's go back to the particles 2d properties right now we're only spawning eight of these that's not very many so we're gonna take that and make that a much bigger number and now we need to talk about color just like we can change the scale over the course of the lifetime we can also change the color go down to color here and we're gonna add a color ramp which is a new gradient texture you click on that and we want a new gradient the gradients start out from black to white but we don't want that we want the initial color to actually be a bright white like it's super hot right at the beginning and then we want to end up at the end somewhere in the red we're also going to drop the Alpha a bit so it like it's fading out and then in the middle we're gonna add some orange so it passes through from white to orange to red as it goes so already looking much more fire-like now another thing we can do is look at the angular velocity and that's gonna give it some rotation and we're going to make that about 350 so you see them all spinning now right so they have a angular velocity of 360 but that's not as good when they're all going the same so if we add in some randomness here we can put a 1 in here and that'll randomize them in different directions so they're all spinning independently and that's good enough pretty close to the sample I showed you at the beginning the only thing that I had done differently was if you go back to particles 2d there is a speed scale and if you double that it'll just do everything twice as fast and there we have it a little flame from our torch here's the original one that I made beforehand pretty close to the same you can see there's all sorts of little tweaking you can do to get everything just the way you want it that's part of the fun of messing around with particles is is you know endlessly twiddling all these little knobs and getting them to do different things for you but that was the main example I wanted to show you now let's look at some other examples of some different kinds of effects you can get from particles here's another example this is almost the same setup almost exactly the same particle material settings with the scale and the color ramp going to a low alpha so it looks like it's fading out the reason it looks so realistically like smoke is that we're using a texture this time it's over here on the particles 2d you can set a texture and we're using this white smoke puffs on there and you can see it looks pretty good looks like smoke coming out and we can even put it to see what it looks like in a scene there we attach it to the little house sprite and it looks like you've got smoke coming out of the chimney something that you normally do is something like this is if you look at the house we took the smoke and made it a child like this and then in the visibility section check the show behind parent that way it looks like it's coming out of the chimney instead of on top of it but that gives you a pretty good effect and there you see it in context of a scene pretty good now another thing you can do with something like this smoke is attach it to a moving object so here's a train sprite and we've attached the smoke the same smoke particles to the smokestack but the problem is when you move the train that smoke stays right there with the Train and that's not going to look natural when the Train moves so what you want to do is in the particle settings you go down here to drawing and there's a checkbox by default it's on called local coordinates and that means the particles stay attached to the local coordinates of their parent now if you uncheck that they become global coordinates and that means that when you move the sprite the ones that have already been emitted are not affected by that movement all right they just come out wherever they are and that means that by adjusting some of the settings with speed and things like that we can get this result and actually in a running scene with the train moving you'll see it looks pretty good leaving the trail behind it as it goes and you could add in some more stuff to make it look more like it's chuck jugging and there's little gaps in the in the flow and all that kind of stuff and this acceleration this is the radial acceleration but we're also doing some tangential acceleration in the you know perpendicular direction of movement so that it streams out behind and you can increase or decrease that based on what your speed of your sprite is I'm going to go through a couple other examples so here we have a chest which is just an area 2d you that has a collision shape on it so that we can detect clicks and you're gonna click on this to collect coins and I'll show you what it looks like and then we'll talk about how this is done so there's our chest when we click on it we get the little shower of coins that comes up from it each time we each time we do it and so what we're doing there is we have our coin emitter and it's set to one shot one shot means it's only gonna happen once when you turn it to emitting the amount of particles is 10 when those 10 particles have have done it doesn't happen again right if we uncheck one shot that would be a constant stream and the reason there's that gap there is because we're using explosiveness explosiveness is how many of those ten to emit at once right for example if I put one on there all 10 are emitted at once the default value is zero which means you get the steady stream so we wanted to just have a little burst of them and we wanted it to be one shot and then if you notice the animation of the coins the animation of the coins is accomplished by the texture the coin texture looks like this so this is a series of animation frames of the rotating coin and we set that as our texture and then we set the each frames to eight because there are eight frames to this animation and then to make that work in the particle material there is an animation section where you can set the speed and tweak it and all sorts of ways to make it run the way you want for a little bit more involved example of this I have this animation of a slime droplet coming off the ceiling and so this is the final frame this is where we want it to stop so we don't want it to loop and so I've set up a little slime dripping from the ceiling particle emitter here and so what's going on here is we've got seven frames of animation and in the particles material we're setting the initial we're setting the speed here but we've unchecked a loop so that when it reaches the drop it stays there but we've also added an acceleration curve and so this curve stays flat for the first part of the lifetime so the drop at the top doesn't move while it's there then the speed ramps up from there so that it starts falling and that's what gives us the following effect and just a couple other examples to give you some ideas here's a little one where whenever we drop the bombs they explode upon hitting so these are rigidbody two DS that delete themselves when they contact an object but they send out a signal to the scene to the parent scene so that it will spawn a particle emitter now a couple of limitations that particle emitters have one of them is so for the explosion you probably want to be you probably want to have it on one shot so that the explosion goes and then it's done but the problem is that when an explosion is or sorry went in it emitter is set to one shot when it finishes so see if I start it if I set it to one shot and let's set it to emit right it finishes the emitting the explosions done the emitting the property is still true so there's no way for us to tell in our code that this particle emissions is actually finished so what we had to do was just create a little timer and delete the particle emitter after enough time has gone by now there's an open issue for this on github so hopefully that gets resolved one way or another either with a mission complete signal or the emission property getting set back to false so you can check for that and you know we'll see how that goes but in the meantime if you're doing something like this and you need to get rid of your particle emitter after it's finished use a timer and you free it when that timer finishes another example is your classic space warp particle emitter where you have the particles coming out from the center of the screen like you're going into hyperspace which can be a lot of fun to play around with and make all sorts of different color effects and glow effects and things like that to give you that impression number of particles can make a huge difference here the key here to getting this effect is taking our texture which kind of an a glow an oval glow shape and in the material setting the align Y property because if we don't set that then the texture is oriented the same way just up and down but by checking a line Y it will align the y-axis of the particle with or the texture I should say with the particles direction and that will give you that much better streaming effect particles can really add atmosphere for example if I turn on the rain here we get one effect or if I turn it off and turn on this other one which I called upside down where we have all these little floaty particles that must mean something's not right and you want to be careful so I hope that gives you ideas for things you can try make on your own when it comes to particles the fun really is in tinkering and trying different things whenever you find something really cool save it somewhere because you never know when you'll need that effect in a game I'll post a link to this project below so you can download and play with it yourself make sure you have Godot 3.0 beta 1 or later thanks for watching and I'll see you next time you
Info
Channel: KidsCanCode
Views: 74,215
Rating: undefined out of 5
Keywords: programming, coding, tutorial, lesson, godot, godot engine, gamedev, game development
Id: awBfTnmgn7k
Channel Id: undefined
Length: 18min 13sec (1093 seconds)
Published: Mon Dec 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.