VFX in Unity: Getting Started
Learn how to create your own custom visual effects using Unity’s built-in Particle System. By Ken Lee.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
VFX in Unity: Getting Started
30 mins
- Getting Started
- Testing the VFX
- Setting up the Testing Environment
- Understanding Particle Effects’ Key Attributes
- Size
- Shape
- Color
- Timing
- Making a Projectile VFX
- Creating the Muzzle Effects
- Making the Base Muzzle Cone
- Defining the Particle’s Shape
- Changing the MuzzleCone’s Color and Timing
- Testing the Muzzle Effect
- Making the Muzzle Flash
- Making the Muzzle Sparks
- Making the Impact Effects
- Adding an Impact Glow
- Fixing the Glow Cut-Off Issue
- Testing the Impact Effect
- Understanding the Projectile Structure
- Making a Projectile Tail
- Adjusting the Tail’s Shape and Size
- Making the Tail Look Fiery
- Testing the Projectile Tail Effect
- Making a Fireball Projectile
- Setting up the Projectile Particles
- Making the Fireball Head
- Making the Primary Projectile Tail
- Improving the Fireball Tail
- Making the Secondary Projectile Tail
- Adding Projectile Sparks
- Where to Go From Here?
Fixing the Glow Cut-Off Issue
You’ve probably noticed that there’s a problem with the Impact effect — namely, half the effect disappears! That’s because part of the Target object renders after the Impact object.
To fix the issue, create a Camera object under the main camera and name it VFX Camera.
Change the properties of the VFX Camera as follows:
- Clear Flags: Depth only.
- Culling Mask: a new layer VFX.
- Depth: 1
Finally, uncheck VFX in the Culling Mask in the main camera.
Select Glow and click Restart to test the result.
Now, the effect should disappear properly. Note that you can only see the corrected effect in the Game View.
Testing the Impact Effect
Now to see the fruits of your labour, time to try the Impact effect in the testing environment!
First, commit your changes by clicking Apply All in the Prefab menu of the Impact object. Then, remove the object from the testing environment. The impact effect will be spawned back into the scene when an actual impact occurs.
Select Shooter in the Hierarchy. Drag the Impact object in Prefabs/VFX to the Impact Prefab field of the Shooter and set Selected Impact to 0.
Click Play to test.
At this point, both Muzzle and Impact are ready, which means you can move on to creating the main projectile effect.
Understanding the Projectile Structure
A projectile effect consists of a head and a tail. The head is the core of the flying body and the tail is a trail following it.
When the projectile only has a head, the visual just doesn’t look right. Adding some particle effects to the tail improves this particular effect quite a bit. You’ll make a projectile tail for the current bullet next.
Making a Projectile Tail
First, create a new prefab from the origin bullet by pressing Command/Ctrl-D to duplicate Bullet_Basic_3dModel in Prefabs/Projectile. Rename it Bullet_Flame_Tail.
Next, drag the Prefab to the test scene and move it close to the gun. Right-click in Hierarchy and select Effects ▸ Particle System to create a particle. Finally, name the new particle FlameTail.
Adjusting the Tail’s Shape and Size
Now, you’ll build the shape and size of the projectile by adjusting some parameters. Make the following changes in Basic:
- Start LifeTime: 0.1 – 0.6.
- Start Size: 0.15 – 0.38.
- Start Speed: 1 – 3.
Then, under Shape, select:
- Angle: 0.
- Radius: 0.1.
- Rotation(Y): 180.
In Emission, change Rate over time to 200. Finally, under Transform, set Position(Z) to -0.75.
Making the Tail Look Fiery
Next, you’ll change the color and texture to make the tail look like fire. Change Color over Lifetime to a fire color palette from one of the presets. This time the alpha value should fade from opaque to completely transparent.
The particle is cooking now!
However, you can improve the effect even more by adding some randomness.
Change the texture of the particle from a circle pattern to a smoke-like pattern by modifying the particle’s material. In the Renderer, change Material to flame_add.
Doesn’t that look more exciting?
Testing the Projectile Tail Effect
Now that everything is ready, you’ll bring the improved bullet to the Shooter Character.
First, save the effect setting by selecting Apply All in the Prefab menu. Then, remove the prefab from the scene.
Drag Bullet_Flame_Tail in Prefabs/VFX to the Projectile Prefab field of the shooter object in Inspector. Set Selected Projectile to 1 so the effect plays by default.
Click Play to see the effect.
Making a Fireball Projectile
Now, it’s time to try another projectile effect — a fireball! You’ll make both the particle’s head and tail this time.
Setting up the Projectile Particles
First, you’ll create a projectile particle effect. Duplicate StarterProjectile in Prefabs/VFX by pressing Command/Ctrl-D. Rename it Fireball.
StarterProjectile already contains a script that handles the projectile’s movement and collision.
Drag Fireball to the Projectile Prefab property of the Shooter character and change Selected Projectile to 2.
Click Play and you’ll see a red dot shooting out from the gun.
Now, you’ll transform that dot into an impressive fireball!
Making the Fireball Head
Your next step is to add a fireball head to the projectile. The head of the fireball is simply a stretched hemisphere with fire-tone colors.
Start by dragging Fireball from Prefabs/VFX to the scene. Move it beside the Shooter character. Doing this helps you tune the particle effect to the right scale.
Select the Fireball particle in Hierarchy. Right-click on it, and select Effect ▸ Particle System to create the projectile head particle. Rename the particle ProjectileHead.
Now, you need to turn the projectile head to a one-shot particle. To do this, go to Main and adjust the following settings:
- Start Speed: 0
- Max Particle: 1
Next, under Emission, set Rate Over Time to 1. Finally, disable Shape.
Then, modify the Renderer settings as follows:
- Render Mode: Mesh.
- Mesh: Mesh_HalfSphere.
- Material: Glow_Add.
- Render Alignment: Local.
Again, you can’t see anything yet because the mesh is too small. Change the Transform Scale to X:15, Y:15, Z:15 so the mesh is big enough to see. Hide the reference object inside the particle effect by disabling its Mesh Renderer.
Here’s the demo:
Now, define the particle shape by changing Transform Scale to Z:55. This stretches the mesh, making it look like the head of a fireball.
Next, modify the particle’s color by enabling Color Over Lifetime. Expand it so that you can select the Color, which opens the Gradient Editor. To finish it off, choose the fire-tone color from one of the presets.
Making the Primary Projectile Tail
With the fireball head ready, you can move on to making its tail!
Select ProjectHead. Right-click, then select Effect ▸ Particle System to create a new particle for the tail. Name the new object FlameTail.
Once again, you need to adjust the shape and direction of the particle. Do this by going to Main and adjusting the following values:
- Start Life time: 0.1 – 0.3.
- Start Size: 0.1 – 0.4.
Under Emission, change Rate Over Time to 50. Then, under Shape, pick the following settings:
- Shape: Cone.
- Angle: 0.
- Radius: 0.15.
- Rotation: Y:180.
After these are done, your fireball will look like this: