Learn EVERYTHING About Particles in Unity | Easy Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome today I'm going to show you everything you need to know to get started making particles in unity I'm going to walk you through setting up three different particles and we'll cover a lot of the options going through those so you can really get comfortable with this as fast as possible I'll also show you how to spawn them into your scene and how to rotate them based on your attack Direction let's get started so we're starting off with a very very simple scene here with basically just a player and some enemies and some grass you don't need assets to follow along with this tutorial however if you like the assets that you see in this project you can download them for free you can use them personally or commercially that's totally up to you I'll leave a link Down Below in the description I hope you enjoy so basically what I've got here is I'm able to damage all three of these objects in the scene here and I really want to spice this up and be able to add some particles when we damage the enemies so we're going to Dive Right In and start off right with a new particle so click here go to effects and click particle system let's call this enemy damage one so this is the default particle system that it will set up automatically if you go down to renderer here you can see it assigned to the Sprite lit default material to it I would like to start off by creating a brand new material let's go into our assets create a new folder called materials open that up and here let's create a new folder called particle system go in there and let's create a new material called enemy damage mat 1 and I would actually like to change the Shader to Universal render pipeline 2D Sprite unlit and the reason I want to select unlit is you can see if we assign this material drag that in there you can see if we dim the global lights these particles are going to show up no matter what so if you would like them to be affected by lights then be sure to select the 2D Sprite lit default Shader I'm going to select a texture here and go with the circle with soft Edge that is included in the asset pack that you can download again it's in the description so let's select that all right so we've got something so if you've never worked with a particle system before this can all be very intimidating looking however you'll find that as you make a lot more particle systems that you start playing around with the same values again and again but we'll go through quite a few of the most common settings right here so I'm going to let this just keep on playing so that I can see what we're changing here now we're going to change the duration over here to 0.25 and that's not going to be noticeable because we are looping right now but the duration is the amount of time that the particle system is actually spawning particles into the world and for a lot of these here I like to change the drop down I'm going to go to start Lifetime and let's choose random between two constants giving it a little bit of Randomness in every way that you possibly can usually results in something that looks a lot better so let's go 0.25 and 0.4 I'm going to move this over so I can see it a little more for our start Speed I'm also going to select random between two constants we're going to go six to eight and let's do our start size and also do random between two constants and go 0.15 and 0.55 so what I would like to get is these particles that when I hit the enemies they're going to shoot out with some Trails behind them it's going to look really nice so next let's change the emission So currently it is spawning 10 particles per second I actually don't use rate over time too too often if we zero that out and if we go right over distance instead what you can see is that will only spawn particles if you are actually moving the object around in the scene and especially if you're going to be using rate over distance the one thing that you really want to know is do you want to be using the simulation space local or world you can see right now with local it's moving the whole particle system right if we change that to world and drag it around you can see how each individual particle kind of has its own spawn point that doesn't change so that's what those do let's zero those out I actually want to go with a burst let's click the plus and actually these default settings things are just fine I'm just going to uncheck looping because that's getting a little bit annoying next let's define the shape of the particle system and get it looking in kind of the right shape that we're going for so let's open shape here now I almost always stick with circle and I'll tell you why I have an orthographic camera right now so you can't tell however for those of you who are using a perspective camera you can see that even though this is a 2d scene if you're using a 3D shape like a cone it's actually going to be spawning particles that get closer and closer to the camera and you might want that but in this case I definitely don't so I'm actually going to leave our camera at perspective to make sure that we don't make that mistake so what I'm going to do is change this to Circle it automatically rotates particle systems on the X by minus 90 degrees let's zero that out and always make sure your z-axis is on zero as well especially if you're working in 2D so I don't want to spawn all of these in a circle I really only want to be using a portion of this circle so for the arc here let's go with 75 degrees and let's rotate it minus 35 on the z-axis now it's already starting to look pretty good there let's add a few more things you can change the radius thickness if you want so you can see I'm changing that line there and that's just keeping the area from which the particles can actually spawn bigger and if I zero that out then it's only going to be able to spawn right on that line so go with whatever your preference is I'm going to leave it at zero next let's choose color over Lifetime and we'll actually need to check that and open it up so this is a gradient here we've got the alpha controls on the top and the color controls at the bottom so for the starting color let's just go with kind of a light red I'm going to insert that there and drag the alpha at the end down to zero so that we get this nice Fade Out next let's also change the size over lifetime select that and open it up and if you click this and nothing appears just drag this bar up I'm going to select this one and add this key up like this so that's going to get bigger really really quickly and then kind of slow down for most of the lifetime of the particle system next Let's Get Some Noise going in here let's open that up noise is really cool and I'll turn looping back on so you can kind of see what this does it's only affecting the position because we've got a 1 in the position amount you can fiddle around with the strength and the frequency to really start adding some Randomness to the movement of your particles and of course you can do that with rotation as well as well as with scale if you really want to I'm going to zero that out and put a 1 back in the position and let's go with one in strength and 1.25 in the frequency let's close that and let's also get some Trails going behind these so as soon as you select Trails here in your renderer a second Trail material slot opens up let's duplicate that first material and name it enemy damage Trail matte 1. let's assign that and open up the trails So currently every single particle is now going to have a trail that follows behind it I think that's a little bit too much so let's go with half the amount let's also make the lifetime only half the lifetime of the particle system I'm also going to give the trails a color over lifetime gradient so I'll go over here and select gradient I'm going to give it that similar nice red color and decrease the alpha at the end as well I'm going to change width over Trail to random between two constants go 0.75 and 1.25 there we go that's looking really nice let's save that as a prefab now so back in our root assets folder let's create a new folder called prefabs and just drag that in there the other really cool thing with particle systems is if you right click that and click effects and go particle system force field add that as a child object of your initial particle system if you go back to your particle system and you enable external forces you can now apply all of these outside forces to your particle system so let's try gravity just as an example it's not doing a whole lot let's increase the range now you can see it's kind of just sucking it back in if we increase the duration in the lifetime you can get some pretty weird stuff happening so I'm not going to save that I just wanted to show that to you I'm going to delete that now before we continue with the next particle systems I'm going to actually get this spawning into our scene when we damage our enemies so if you want to know how to apply damage to various objects in your scenes this guy has just a grass script but it also has Health this guy has an enemy Health script yet you want to know how to damage both of them I do have a tutorial that can show you how to do that however you can spawn this particle system in wherever you are actually applying damage to your enemy or if you just want to test it out you can code it so that whenever you hit the space bar or something it'll spawn somewhere it's very very easy to set up I'm going to open up my enemy Health script as well as my grass script and I really just want to add a serialized field private particle system damage particles I also want to create another private particle system called damage particles instance so this is going to be a reference to our prefab but this is going to be a reference to the instance of each individual prefab that we are spawning into the scene in case you want to change any of the settings within the particle system I just want to instantiate the particle system right here in the damage function I'll create a new function for that called private void spawn damage particles so we're going to say damage particles instance is equal to instantiate or do we instantiating the damage particles where do we want to spawn this at the current transform dot position and we want to spawn it in with no rotation so quaternion.identity let's call that here same thing in Miami Health script I'm going to click on my first enemy and now you can see there's this damaged particles here let's drag in our prefab and let's test that out okay so you can see that that worked but there are also three particle systems Stuck in My Scene here and we don't want those clogging up our memory we want to get rid of those as soon as the particle systems are done playing so to do that we're going to open up our prefab and down here at stop action select destroy let's try that again all right you should now see them coming in and then destroying themselves as soon as they're done playing there we go great now let's get another particle system going and this one I want to spew out and I want to have it kind of like splatter when it hits the ground and kind of turn into another little mini particle system and I would also like them to kind of be rotated in the direction that they're traveling so I'll show you how to set that up so first let's create a new particle system hold enemy damage too I'm going to reset the transform and just move it over here I'm going to create a new material for that I'm just going to duplicate enemy damage matte 1 rename that to enemy damage mat 2. and assign that material down in the renderer okay so again you can see that they're kind of shooting off into the distance there that is again because of our perspective camera so let's actually change the shape first change it from cone to Circle and we're going to make the arc only 70 degrees let's rotate it on the z-axis by minus 30. great let's make the duration of this system 0.25 seconds I am going to make the lifetime speed and start size all random between two constants for the lifetime let's go 0.85 and 1.25 for the speed let's go six and eight and for the start size 0.2 and 0.6 I'm also going to change the gravity modifier to random between two constants and make that one and 1.5 let's also turn on collisions for this so nothing's changed yet so we want to open that up we definitely don't want planes we want to select world and mode we want to set that to 2D and now it's going to collide with absolutely anything that has a collider so let's go ahead and I'm going to change that to just ground so these are bouncing around like crazy and I don't want that so I'm going to change the bounce to zero and now they're sliding all over the place and I don't want that either so I'm going to change the dampen to two one okay let's also enable color over lifetime always nice to get a nice Fade Out let's also open up a mission and get rid of rate over time and add another burst let's turn off looping while we're up here let's change stop action to destroy so that just like the other one it doesn't end up clogging our scene it'll destroy itself when it's done playing I'm also going to change the size over lifetime I'm gonna make the starting point 0.7 just like that that's great now you can see as we're shooting them out they're still perfect circles but if we go down here to renderer and we change the render mode from billboard to stretched billboard now you can see they're orienting themselves in the direction of their velocity which looks really nice now I would like some sort of reaction to happen when these things actually collide with the ground so we want a sub emitter go ahead and select that and open it and we want to create a sub emitter on a collision let's click the little plus button right here to create a new sub emitter particle system what that does is that'll create a new child particle system called sub emitter and it'll automatically assign that right here so you can look here and you can inherit a few things if you want or you can totally change everything yourself so off the bat it's looking a little bit weird and the reason that it's behaving so strangely is because back in our parent particle system the lifetime loss here is set to zero which means that the particle is sitting there on the ground not dying right away and it's just spawning a sub emitter again and again and again which is taking it above its Max particles of 1000. so what we want to do is in the parent down here in Collision we want to change the lifetime loss to one now you can see if we hit play it looks a little better anyways so let's go back to our sub emitter and open up the renderer and assign the same material as our parent material now the sub emitter is just a little too much so let's tighten some of those things up I want this to be really quick so we're going to do 0.25 for the duration I want my lifetime to be random between two constants and the speed and the start size we're gonna go 0.2 and 0.25 for the lifetime six and eight for the speed and 0.1 and 0.2 for the start size constrain this for just a second and make it 0.7 said gravity of 1.25 it's looking good it's just a little bit much let's bump the emission bursts down to 20 and let's make this shape a circle full circle is totally fine and let's again do the color over lifetime to make sure that we get a nice gradual Fade Out there you go if we assign that one as a prefab let's click on our enemy 2 and assign that one and test it out you'll notice if you attack them from the other side that the particles still go in the same direction I'll show you how to fix that very shortly but first let's get rid of this and I want to create our last particle system which is going to be the grass being cut apart here so let's go to effects particle system call it grass particles let's reset the transform I'm going to move that down here over the grass and let's duplicate enemy damage Mat 2 and call it grass damage mat I'm going to go to the texture here and I'm going to select the stems texture that is actually three separate Sprites in one so I will show you how to deal with that let's go ahead and assign that material to the renderer okay so right off the bat this is looking pretty weird it's just spawning three grass blades beside each other so what we're going to do to handle that is select the texture sheet animation so this is a grid and it was a three by one grid so now you can see it's only spawning in one grass stem at a time however if you watch them they're kind of animating through all three of the Sprites and that's not what we want but we've got this start frame option here so I'm going to select that and open random between two constants and I want the start frame to be somewhere between 0 and 3 and I'm going to change the frame over time to a constant zero there you go so now it'll just pick one and it'll stick with it the entire time even though if you look this was the Sprite in the editor right so we're having to cycle through these three different ones so next let's bump up the start size a little bit get them matching our actual grass in the ground here our duration is going to be 0.2 let's change the start Lifetime and start Speed to random between two constants we're going to do 0.85 and 1.5 and a speed of 0.25 to 0.55 this is going to be pretty slow I actually also want to check the 3D start rotation and let's change that to random between two constants and I want to randomly rotate the starting rotation of these grass blades between 0 and 360 on the z-axis I'm going to change the gravity modifier to 0.2 let's uncheck looping and change the stop action to destroy let's change the emission from rate over time to a burst let's see how 20 looks let's make sure that our shape is just a circle let's make it fade out over time again so color over lifetime you know the drill put that there and change the alpha to zero let's also get them rotating a little bit over their lifetime you could do this with noise but we can also do rotation over lifetime let's separate our axes so we get the separate X Y and Z let's change this to random between two constants let's say anywhere on the Z from minus 45 to 45 now you get this nice kind of slow rotation happening over their lifetime great okay let's make that a prefab let's delete that let's go to our grass and drag that in and let's test that awesome all right and last but not least I want to show you how you can fix it so that even if you're attacking from another Direction you can actually get the particles traveling in the direction that you want them to be going in so my grass and my enemy Health they are both implementing an eye damageable interface and I'll open that up for you I cover all of this in my melee attack tutorials so I'll just show you the script really it's just public interface eye damageable with a public method and a public pool and then over here an enemy health and in Grass we just add a comma after monobehavior and add eye damageable you then have to add the public pool as well as the public method and as you've already seen we are spawning in the damaged particles in our actual damage function so since I have both of these scripts coming from an actual interface here what I would like to do is go into my interface and add in a vector 2 attack Direction now you can't get an interface wrong because honestly when you go back to your scene you're going to be flooded with errors as soon as you change something and that is because we are not implementing the new change that we just made it's really it's just complaining that in my health scripts I am not including our new parameter of Vector 2 attack Direction so we don't know what this is yet right I haven't showed you where this damage function is actually being called from this is just a blank that can be filled in from the source but since we have this in here we can actually code the rotation right now so what we're going to do is inside our spawn damage particles let's add a quaternion called spawn rotation that's going to be equal to equal turning and Dot from to rotation now we're going to be calling this from a vector2 DOT right and the reason we're doing that is because this is literally from 2 we literally set this up pointing to the right we could face this up right and call and instead put in Vector 2 dot up here but let's just stick with what we already had so We're translating it from a vector2. right and what's our two directional R2 direction is going to be the attack Direction so what we want to do is in spawn particles here we want to pass in Vector two attack Direction that here now it's going to want that in these brackets here so we will pass in attack Direction over here I'll just copy and paste this into my other enemy scripts as well [Applause] so now our very last error is actually pointing to our player attack where we are passing in I damageable dot damage we're passing in the float that it wants but now we need an attack Direction and with the way that my character works the attack direction is simply just his transform dot right now the very last thing that needs to do is when we actually do the spawn damage particles you can see here when we're instantiating our particles we passed in quaternion.identity we now want to put in our spawn rotation instead and let's test that awesome well there you go guys I hope you enjoyed if you found this video helpful please give it a like it really helps grow the channel and let me know down in the comments if you have any ideas for future tutorials you'd like to see thanks so much for watching bye
Info
Channel: Sasquatch B Studios
Views: 6,339
Rating: undefined out of 5
Keywords: unity tutorial, unity 2d, particles, particle systems, unity particles, unity beginner tutorial, sasquatch b, unity learn how to make particles, unity learn particles, unity particle basics, unity learn particles for beginner, particle system, unity particles for beginners, unity particle tutorials, unity particle system, unity how to make particles, unity how to get started with particles, game development, tutorial, learn, learn unity particles, unity tutorial for beginners
Id: 0HKSvT2gcuk
Channel Id: undefined
Length: 19min 15sec (1155 seconds)
Published: Thu Dec 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.