Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Hands-On Unity 2022 Game Development

You're reading from   Hands-On Unity 2022 Game Development Learn to use the latest Unity 2022 features to create your first video game in the simplest way possible

Arrow left icon
Product type Paperback
Published in Oct 2022
Publisher Packt
ISBN-13 9781803236919
Length 712 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nicolas Alejandro Borromeo Nicolas Alejandro Borromeo
Author Profile Icon Nicolas Alejandro Borromeo
Nicolas Alejandro Borromeo
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Creating a Unity Project FREE CHAPTER 2. Editing Scenes and Game Objects 3. Grayboxing with Terrain and ProBuilder 4. Importing and Integrating Assets 5. Introduction to C# and Visual Scripting 6. Implementing Movement and Spawning 7. Physics Collisions and Health System 8. Win and Lose Conditions 9. Implementing Game AI for Building Enemies 10. Materials and Effects with URP and Shader Graph 11. Visual Effects with Particle Systems and Visual Effect Graph 12. Lighting Using the Universal Render Pipeline 13. Full-Screen Effects with Post-Processing 14. Sound and Music Integration 15. User Interface Design 16. Creating a UI with the UI Toolkit 17. Creating Animations with Animator, Cinemachine, and Timeline 18. Optimization with Profiler, Frame Debugger, and Memory Profiler 19. Generating and Debugging an Executable 20. Augmented Reality in Unity 21. Other Books You May Enjoy
22. Index

Creating fluid simulations

As we said, the best way to learn how to create particle systems is to keep looking for already-created particle systems and explore how people have used the various system settings to create completely different simulations.

In this section, we will learn how to create the following effects using particle systems:

  • A waterfall effect
  • A bonfire effect

Let’s start with the simplest one, the waterfall effect.

Creating a waterfall effect

In order to do this, follow these steps:

  1. Create a new particle system (GameObject | Effects | Particle System).
  2. Set Shape to Edge and its Radius to 5 in the Shape module. This will make the particles spawn along a line of emission:

Figure 11.22: Edge shape

  1. Set the Rate over Lifetime of the Emission module to 50.
  2. Set the Start Size of the Main module to 3 and the Start Lifetime to 3:

Figure 11.23: Main module settings

  1. Set the Gravity Modifier of the Main module to 0.5. This will make the particles fall down:

Figure 11.24: Gravity Modifier in the Main module

  1. Use the same Explosion material we created previously for this system:

Figure 11.25: Explosion particle material

  1. Enable Color Over Lifetime and open the Gradient editor.
  2. Click the bottom-right marker, and this time you should see a color picker instead of an alpha slider. The top markers allow you to change the transparency over time, while the bottom ones change the color of the particles over time. Set a light blue color in this marker:

Figure 11.26: White to light blue gradient

As a challenge, I suggest you add a little particle system where this one ends to create some water splashes, simulating the water colliding with a lake at the bottom. Now we can add this particle system to one of the hills of our scene to decorate it, like in the following screenshot. I have adjusted the system a little bit to look better in this scenario. I challenge you to tweak it by yourself to make it look like this:

Figure 11.27: The waterfall particle system being applied to our current scene

Now, let’s create another effect: a bonfire.

Creating a bonfire effect

In order to create a bonfire, do the following:

  1. Create a particle system like we did in the section Creating a basic particle system with Shuriken, in GameObject | Effects | Particle System.
  2. Look for a Fire Particle Texture Sheet texture on the internet or the Asset Store. This kind of texture should look like a grid of different flame textures. The idea is to apply a flame animation to our particles swapping all those mini textures:

Figure 11.28: Particles texture sprite sheet

  1. Create a particle material that uses the Universal Render Pipeline/Particles/Unlit shader.
  2. Set the flames sprite sheet texture as the Base Map.
  3. Set the color at the right of the Base Map to white.
  4. Set this material as the particle material. Remember to set Surface Type to Transparent and Blending Mode to Additive:

Figure 11.29: A material with a particle sprite sheet

  1. Enable the Texture Sheet Animation module and set the Tiles property according to your fire sheet. In my case, I have a grid of 4x4 sprites, so I put 4 in X and 4 in Y. After this, you should see the particles swapping textures:

Figure 11.30: Enabling Texture Sheet Animation

  1. Set Start Speed to 0 and Start Size to 1.5 in the Main module.
  2. Set Radius to 0.5 in Shape.
  3. Create a second particle system and make it a child of the fire system:

Figure 11.31: Parenting particle systems

  1. Apply the Explosion material from the explosion example.
  2. Set Angle to 0 and Radius to 0.5 in the Shape module.

The system should look like this:

Figure 11.32: Result of combining fire and smoke particle systems

As you can see, you can combine several particle systems to create a single effect. Take care when doing this because it’s easy to emit too many particles and affect the game’s performance. Particles are not cheap and may cause a reduction in the game’s FPS (Frames Per Second) if you are not cautious with them.

So far, we have explored one of the Unity systems that you can use to create these kinds of effects, and while this system is enough for most situations, Unity recently released a new one that can generate more complex effects, called Visual Effect Graph. Let’s see how to use it and see how it differs from Shuriken.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime