Triggering Impact Particle - Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to create a impact particle like this that will be slightly randomized and give a really good inflection for something that happens within the game let's actually make a new scene and set this up from scratch in my new scene I'm going to create it's actually just create a little setup here so we will do a plane and we'll zero that out next I'm going to create my particle effect to do that right-click effects particle system I'm also going to zero this out and actually so that we can see it in three-dimensional space I'm just going to pull this out for now now I'm going to walk through a series of attributes that we can change to affect the behavior of this particle now remember what I want to do is I want it to burst outwards from the center and the default has a looping a cone shape so we're gonna have to make a lot of changes the first thing I want to do is I want to turn off looping now looping is good if you want a persistent particle effect inside of your environment or you want something like a like a torch or a fire trail behind your player but for me I want a one time quick burst of particles I'm going to turn off looping also I do not want it to play on awake I want to tell it when to create this burst so I'm also going to disable an awake the last attribute that I generally change when I'm making a new particle is simulation space it will default to local this means that if I were to put this as a child underneath another object so a are to make a player for example and I were to put my particle system underneath there and then I rotated my well let's actually turn this on and I were to rotate my player see how the particles would rotate with that I don't want that to be the case I'm going to ungroup that and delete my player I want my particles to just exist inside of the world and use their own transformation so I don't want them to inherit transformations from a parent I just want them to exist inside the world so to do that I'm going to change the simulation space to you world instead of local let's actually save our scene to control s inside my scene so we'll call this a particle scene I mentioned that I want my particle to behave as a burst and a sudden quick burst of particles to do that I'm going to expand the emission down here and I'm going to add a burst I'm going to click this little plus button so what this is going to do is if I press the little play preview right here it will add about of bursts but then we also get this steady stream of particles afterwards that is because we are adding a burst but we're also up here defining a longer duration so what I want to do is I want to just keep that burst but I don't want the trail afterwards you know if you if you did want that you could keep that as well let me turn the duration down to zero so now we just have the sudden burst effect like that the next thing I want is I want this to burst outwards in a sphere right now it is bursting outwards and a cone to change that I'm going to come down to shape you'll see the shape down here and you could actually you know make a wider cone if you wanted to do something like that but actually I want to change this shape to a sphere instead so now we have a sphere so it's looking a little bit better that is something that will already communicate a burst of collecting or a burst of some sort of impact you could already use that but we want to make it a little bit fancier than that if you want to create an effect of a stretched almost like a lined effect instead of a square down and renderer we could change this from renderer mode billboard to stretched billboard and what that's going to do is this show it's going to stretch it in the outwards motion of its path so you see how we're getting this elongated sphere in this case it will stretch your sprite so just keep that in mind it's it's a really cool effect but you may want it you may not I think it's going to work really well for the effect we're trying to create so I'm just gonna keep that on right there now the next thing I want to do is I don't really like this fuzzy particle now I could create my own sprite and I could put this on the sprite and my own sprite could have different effects and you can do stars or some harder-edged as a really simple example I'm just going to change this default default particle system from this to a sprites default which you'll see is just going to add a solid color inside of the entire particle sprite image down here so it's going to do that again you could create your own custom sprites if you want but for me just for demo purposes we keep this at sprites default and so now we're getting something like this so this is already looking a little bit better but the next thing I notice is that my size on my particles is a little bit too big so to change that I'm going to scroll back up into start size at the very top I'm gonna change that from 1 to something like point 2 and a lot of what I'm doing here I've figured out some values beforehand but a lot of it is tweaking so you know for example if we have point 6 we will play that and say you know what maybe that's a little bit too big or maybe for your purposes it's what you want but let's turn that down to something like point 2 that's looking closer to what I want it I could even imagine this going even lower if you want another thing you could do let's say that I don't like that all of these particles are the exact same size what I could do is I could add a randomized element so that each particle when it is spawned is spawned at a slightly different value so to do that under start size this little arrow at the very right if you click this and you go to random between two constants this will allow you to define two different values that it will use to determine the size of this particle or you you might also see that a lot of other attributes give this option so if you want a randomized value between two points just know that you can click this and define that so I'm probably gonna do this on a few other attributes as we work through this so start sighs let's put this maybe I want points you to be around the average but let's give it the ability to go smaller so point one and the ability to go larger so I'll do point three let's look at that okay little bit better I actually kind of like that and you'll notice there is some difference in the size vary between all of my particles I don't like this really slow moving speed I want a really quick burst to effect that I want to come up to start speed it starts off at five let's bump this up to something like twenty or thirty okay that's that's got a lot more impact to it start life time you'll see that these particles exist for a very very long time if i zoom out that's way too long I don't want them to exist that long so I'm going to come up to start a lifetime and I'm going to change that to something much much smaller it's a 0.5 maybe okay that's actually pretty good I'm going to turn that down even lower again this is the mess with it until it looks right method okay so just a really quick burst and then the particles go out okay so we have our life time much shorter and you know after I made the life time shorter I think it'd be really cool if instead of all the particles shooting out at max speed if I could have varied speeds so that some particles will go slow and end up towards the center and some will go really fast and end up at the edge you'll see that the effect that's created is that everything just moves outwards really quickly I want some particles still be floating around the center so I'm going to change the start speed from a flat 20 to a random between two constants between something like let's do 5 and 30 maybe okay so you'll see how some particles are ending around this point and some are ending way out here actually like that effect even though some particles are moving slower and some are really fast they're all disappearing at the same speed maybe I want their lifetime to be slightly varied as well so I'm going to come back up here to start life time will change this random between two constants and I'm just going to do point two and point four and it is a little bit subtle but you'll see how they start disappearing at different rates I think that looks a little bit more interesting now we still only have a generic white color so let's change the color now do something more interesting and I'm going to do a randomized color you know you could do a flat color like this if I make a let's do an orange but I think it'd be more interesting if we have a little bit of color variation here so I'm going to do again start color random between two colors this little drop-down on the right change that something lighter orange something like that we'll see how we get the subtle variation and I like the look of that a little bit better it's just more interesting a little bit more complex so let's keep that and the more I press this button the more I'm seeing I think I want more particles I think 30 down here is not enough so to changed that if you go down to a mission and burse this is my count this is my number of particles in my burst the bump that up to something like 50 there's more particles it just feels a lot better and when I bump those particles up I can more clearly see the differentiation between my random values you'll see that I have more in the center and more on the out you know I can even bump that up even more if I wanted the 70 looks even crazier they have to end up somewhere between so something like 16 okay great I like that the last thing that I'm noticing in my out words burst is that all of my particles are disappearing instantaneously I think it would look a little bit more interesting and realistic if my particles had a subtle fade right at the end before they just pop out of existence so to effect that I'm going to scroll down to color over lifetime and I'm going to expand that make sure you click the little checkbox in order to tell it to use this setting and right here in color over lifetime if you click that mainly right now I care about the opacity and this is this is actually blending this color if you click this little top arrow right here this is saying the opacity at the start of the particle lifetime will be full opacity and if I click the little arrow over here it will also be full opacity now if I do something like this if I click on the last arrow and I change this to zero you'll see the effect this has is this is slowly fading out my particle from 100% opacity to 0% opacity over time so if I do that and I hit play you see I don't really like that either it's fading out too quickly I wanted to maintain max up a s'ti until towards the very end and then fade out very quickly so to do that I'm going to open back up my color over lifetime and I'm going to click right here to add another little arrow at the top and that is Maya pasady you could think of this as a keyframe so at this point in time it said max capacity at this point in time which would be somewhere around say 75 percent or you could just click and drag to reposition this you know if you accidentally click and make an extra you know is just select it and delete it so I'm gonna make this somewhere around 70 you'd also put the value in there if you want to be exact and at 70 I want it to be full opacity so I'm going to change that back to 255 so this is going to be full opacity until right around 70 percent of its lifetime and it's going to fade out very quickly let's see what that looks like okay it's kind of subtle but you'll see how it's not an instantaneous pop out at the end it's a fade-out towards the very end of its lifetime just say I like the look of that and we're actually done with the meat of our generic impact particle you know this looks pretty decent for most effects and we could create multiples of this and change the colors for different sorts of effects or the speed and and the shape I want to revisit one last attribute to tell you if you wanted to keep experimenting with this stuff this stretched billboard will lock out a few other things like rotation so if you prefer the effect of billboard so I'm gonna change that back to billboard you see the effect is these these particles outwards rather than that lined effect you could actually do this and then do something with for example trails so if I enable trails and you'll see that it's missing a trail renderer down here if you click play you'll see how it's it's purple if you scroll down to the bottom and renderer if you do trail material and you change that to default line so you can make these trails and it's kind of crazy you can tone this down with I believe it's inside of trails the lifetime put that down to like point to you know we're creating a very similar effect one may be without the stretch billboard so just two different options for you right there you know what I kind of like this better now that I'm looking at it you know let's let's do a variation let's do two random constants between 0.05 and maybe 1.5 or sorry 0.15 that'd be better you see how there's varying trail lengths let's say that we like that a little bit more again just other options for you there's so many other things you can do you can change the velocity of your lifetime the rotation you could add a gravity to it if you want there's so many things to mess around with this is the basics of it so I'm going to clap some of this okay so we can play that we can see the effect now the next thing I'm going to do is show you how to trigger this effect at runtime because I do want to tell this to play a burst when a game event happens so to do that we're going to mock up a player so I'm just going to do 3d object cube you know in a real world scenario you want to make this the maybe the art and the Collider a you know a sub object or now I'm going to call this player okay and I'll reposition this at zero zero zero I will pull this upwards a little bit to say 0.5 now one way to trigger a particle effect is if in a script I can get a reference to a particle system I can play it so what I'm going to do is I'm going to real able my particle system we will pretend that this is a generic collect particle and I'm also going to zero this out as well so now we have our collect particle down here let's say that I want my collect particle to appear outwards from the player kind of like that and just because I want this to look a little bit better I'm going to create a material for the player big fat blue blueish I'm going to apply that great so we have our player of our collect particle like that now what I want to do is to maintain the reference of this particle effect I actually want this to be part of the player so I'm going to drag and drop this underneath the player object so now the collect particle will be a child object meaning that if I move the player around so you'll pull the player up right there if I play the particle it's still coming outwards from the player so the last thing I need to do is actually create a script on the player to reference the particle and tell it to play so to do this I'm going to create a script so down in assets right click create c-sharp script I'm just going to call this player no this could be any other scripts the code would be the same for now we want to imagine this existing on the player and the player is going to have a graphic for collecting I'm going to get rid of all this at the very top I'm going to expose a reference to a particle system and we'll call this the elect particle I'm also going to assign this to null just because that's what it will be anyways I just want to be really clear and this will clear out most editor warnings that you'll see pop up because something doesn't have an initial value this will minimize that now for testing we are going to simulate to input get key down let's just test it from the spacebar press and when we press spacebar we are going to collect a thing now what does that mean well we'll create a function or collect now maybe I imagine this would even be something public that another script could call now when we collect something we want to play the collect graphics later on we may want to play the collect sound effects - but our collect graphics is going to be our particle so at this point if I created a container to store a reference to a collect particle down there we'll store it inside of the player and we'll fill that in and the inspector by using serialize field and to play it it's as simple as collect particle dot play so what we're doing here is we're just using this for testing so I'll leave a little little note for myself to do delete after finished testing so now inside of update we're detecting what if we press the spacebar and if we did play our collect particle that we referenced in our scene now the last thing we need to do if you save your script we're telling it to play but if you look on your player right here we still have not told at which particle we want to play and the particle we want it to play is this child object that we created so if we drag and drop there the player script is now referencing the collect particle that is a child so when we press spacebar this collect particle will play its associated particle effect right we save that come back here we make sure that we referenced it we hit play now if we click down in our scene and we press spacebar we are simulating the action of collecting a thing and playing The Associated particle effects so as long as you have a particle effect that you can reference and generally I like to do this as a child object on your character or your enemy or your kill volume or whatever it is you can play a burst particle effect to create that really interesting feeling that we get when when we want to communicate something happened right took damage collected a thing fired off the rocket launcher or whatever else you want it to be so I hope this helped you out this is you can reuse this particle effect set up and you could duplicate that you can make this a prefab if you want but I think it's just really helpful to have a very clicking dirty go to particle effect to communicate a interesting game event
Info
Channel: ACDev
Views: 49,541
Rating: undefined out of 5
Keywords: Unity, Particle, Burst
Id: BXh6LC1H5S0
Channel Id: undefined
Length: 21min 23sec (1283 seconds)
Published: Sun Sep 15 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.