#100DaysOfGameDevGame DevTrainingUnity

2D Game Development – Visual Styling: Particles

Day 066 #100DaysOfCode
Day 021 #100DaysOfGameDev

slicing the VFX Sprite Sheet into individual Sprites

Now it’s time to tap into Unity’s extensive Particle System and add some cool effects to the level. The first step was to load the Sprite Sheet containing the visual effects and slice it up into usable pieces with the Sprite Editor.

Smoke Effect

To create a new Particle Effect we need to use Create at the top of the Hierarchy window and select Effects > Particle System. This creates an instance of a new particle generator in the scene. There are a lot of settings available in the Inspector for the particle system, but right now I just want to go down to Texture Sheet Animation, check it, and expand its settings.

settings for the Texture Sheet Animation

Normally, the settings in this section are used to animate the particle image over time but in this case, the plan is to use it as a way to pick a random sprite for each particle instead. The Mode is set to Sprites and by clicking on the + button next to the sprite entry that appears so there will now be two entries. The two Smoke sprites that were separated out from the vfx sprite sheet can now be dragged over to these spots. Now in the Scene View the particles that are being generated are one or the other smoke sprites at random.

Next is to change how they are created because right now they are spread out way too far and in too many directions. This is going to be the smoke for the robots that signifies that they are broken, so it has to be reigned in a little.

Shape settings

To make the Smoke look better there needs to be some key steps. First, in the Shape section in the Inspector, the Radius needs to be set to 0. This causes all the particles to be generated from a single point. Next, the Angle is reduced to 5 to really close it up and make the Smoke look like it is rising as a plume now. The particles are still moving too fast and, being all roughly the same shape, seem a bit unnatural.

To bring a certain level of randomness to the particles three more settings need to be adjusted. Start Lifetime is how long a particle is on screen before it gets destroyed by the Particle System. Start Size is the size of a particle as it gets created. Start Speed is the movement speed of a particle. By bringing some variety to all of these settings, the Smoke that is generated can look more believable. The particles still “pop” out of existence, so it still looks a little off.

By using Color Over Lifetime the color and transparency of the smoke can be altered to make it look more believable.

The same goes for Size Over Lifetime, which can be used to make the particles look like they are dissipating and trailing out.

With the Smoke Effect created it can now be added to the Robot prefab so they can truly look broken. A problem arises, however. The smoke moves with the robots, which isn’t too believable. The particles shouldn’t follow the robot movement. Also, if Ruby fixes a robot, they continue to smoke when they are supposed to be fixed. This needs to be fixed. For the smoke movement this is easy, change the Simulation Space setting of the Particle System from Local to World. Now the smoke trails behind the robots rather than staying with them.

To make the smoke stop when a robot is fixed, the EnemyController script will have to be modified. By declaring a new public variable of type ParticleSystem the Robot Prefab can now receive the smoke effect that was created. This is a ParticleSystem type and not a GameObject type because if a public member is a Component or Script type (instead of GameObject), when you assign a GameObject to it in the Inspector then Unity stores the component of the type that is on the GameObject. This prevents having to do GetComponent in the script like has been done before. It also prevents assigning a GameObject that doesn’t have that component type on it to that setting, which avoids creating bugs by mistake.

In the Fix function of the EnemyController script, add a line and the smoke will now stop when a robot is fixed.

The Stop command is used rather than Destroy because Destroy would eliminate the particle effect instantly, even particles that are not finished rendering fully yet. By using Stop, the system comes to an end in a more believable manner.

Particle System at work

Leave a Reply

Your email address will not be published. Required fields are marked *