Collision Effect

Particle System Beginner


A generic square placeholder image with rounded corners in a figure.
Breaking stuff!

Introduction

In this tutorial we will be creating a cartoon-styled collision effect that is displayed whenever an object falls or gets bumped into something. We will start by creating some sprites for the effect. Next, we will put these sprites in a particle system and customize it to our liking. Finally we will write some scripts that determine when to spawn the effect.


Tilesheet

I created 4 colored stars in Adobe Illustrator and aligned them in a grid with a transparent background. It is important that these images are perfectly aligned in the grid because later in Unity, the particle system will try to separate them.

Download Tilesheet

A generic square placeholder image with rounded corners in a figure.
The stars aligned in 2x2 grid.

Particle System

Next, in Unity, we will first create a material that uses our tilesheet. I will be using the Mobile/Particles/Alpha Blended shader that's built into Unity.


A generic square placeholder image with rounded corners in a figure.
Collision material.

When importing the tilesheet as a default texture into Unity, it is also important to check that Alpha Is Transparency is toggled on.

Next, we will be creating a particle system that can emit these star particles. In this particle system we will customize different sections.


Property Settings
General
Emission
Shape
Size over Lifetime
Noise
Texture Sheet Animation
Renderer

Once the particle system is done, we turn it into a prefab called Collision Effect. We will later spawn this prefab when needed.


Collision

In this final section we will be writing an ImpactCollision.cs script that detects collision and spawns the particle system. You can find the script here. https://pastebin.com/BB55A3ZS



A generic square placeholder image with rounded corners in a figure.
Impact Collision Script.

In the script we assign the particle system prefab. This prefab will spawn whenever the Minimum Effect Force has been reached. When the force is even stronger and the Minimum Break Force is reached, the object will break and a Destroyed Version prefab will spawn. The script also rotates the particle system around the object. To use the script, just assign it to an object in your scene. The object also needs a collider and a rigidbody.


What's Next?

This effect was made for a game I'm working on. I have drawn some other cartoon-looking particles and I will be using them more in the context of player/NPC interaction and dialogue.


A generic square placeholder image with rounded corners in a figure.
More effects.



Want to support me in creating free Unity tutorials and content?



Questions about this article?

Send me a message