Particles

From Unity3D

Jump to: navigation, search

Contents

General

Particles are basically just 2D planes with textures on them. Particle systems can be used to emulate special effects like fire.

Since Unity 3.5, Unity has implemented a new particle system called Shuriken

For extensive information on modules in Shuriken in Unity, visit this link: http://docs.unity3d.com/Documentation/Manual/ParticleSystemModules.html

The legacy particle system is still made available and more details about them can be found at http://docs.unity3d.com/Documentation/Components/comp-ParticlesLegacy.html

Good Practices and Tips

  • Particles should only be used to "beautify" a scene.
  • Particles' start lifetime should only be as long as it is needed.
  • Do not worry about the amount of particles you use, unless they have a very long lifetime.
  • Particles can be used to simulate many things, not just explosions or fire. Particles can be things like ripples on the water to hyperspace to fish!
  • If a particle looks weird, try experimenting with material you are using. Make sure the material shader is set to Particle/ and not Diffuse. Experiment with the different particle shaders, and maybe even write your own!
  • If your particle system doesn't look the way you want it, there are probably options you can adjust to make it more to your liking. Check out the different modules and properties in the particle systems and find out what they do!

Shuriken vs Legacy Particle System

  • Some of Shuriken's module's properties cannot be accessed through code as of yet (Unity 3.5.0b6)
  • Legacy Particle System's properties can be accessed through code.
  • Shuriken's system is more robust and include curves for much more customization through the inspector.
  • Some people find the Legacy Particle System more intuitive while other people find Shuriken more intuitive.
  • It doesn't matter which particle system you choose, many of the properties in both systems are similiar.

Accessing Shuriken through code

The biggest caveat of Shuriken is that most of it's modules cannot yet be accessed to code, but if you don't need to do that, use Shuriken as much as you want. However there there are still many properties you can access. For more reference go to http://docs.unity3d.com/Documentation/ScriptReference/ParticleSystem.html

However you should be able to turn emission on and off:

//Some particle system you dragged in in the inspector
public var particle_system : ParticleSystem;

void SomeFunction() {
  particle_system.enableEmission = false;
}

If you want to emit particles in bursts:

//Some particle system you dragged in in the inspector
public var particle_system : ParticleSystem;

void SomeFunction() {
  particle_system.Emit(30); //emits 30 particles
}

Careful running this in Update() because you might not want to emit 30 particles every update.

You can also edit the particles in the emitter - this is probably what you want to do other than turning emission on and off.

//Some particle system you dragged in in the inspector
public var particle_system : ParticleSystem;

//array to hold particles
//array size should be the same as your max particles value in the Shuriken Particle System
private ParticleSystem.Particle[] particles = new ParticleSystem.Particle[1000];

void SomeFunction() {
  //load particles into array and store amount of particles
  int length = particle_system.getParticles(particles);
  
  //change properties of particles
  for(int i=0; i<length; i++) {
    particles[i].color = new Color(1,1,1,1);
  }
  
  //load particles back into the Shuriken Particle System
  particle_system.SetParticles(particles, length);
}

Current Properties in ParticleSystem.Particle

  • angularVelocity
  • color
  • lifetime
  • position
  • randomValue
  • rotation
  • size
  • startLifetime
  • velocity

Rendering Particles

This is it's own section because the particle renderer changes some important properties in particles that can be used to simulate different effects.

In Shuriken under the Renderer Module and in the Legacy Particle Renderer under Stretch Particles there are the following properties:

  • Billboard
    • Default, Best for regular particles like explosion or splashes.
  • Stretched/Stretched Billboard
    • Use when you want the particle to follow in the direction of the emitter. Useful for speed lines or flocks of animals.
  • Horizontal Billboard
    • Use when you want the particle to be flat horizontally. Useful for water ripple effects.
  • Vertical Billboard
    • Use when you want the particle to be flat vertically. Useful for effects on walls.
  • Mesh/Legacy Mesh Renderer
    • Use when you want the particles around a mesh. Best substitution for "3D" particles.
  • Sorted Billboard (legacy)
    • The particles are sorted by depth. Use this when using a blending material. You probably wont need to use this.

Particles

  • To use the Shuriken particle system, go to GameObject -> Create Other -> Particle Systems.
    This will create a very basic particle system for you to play with.
  • There are many modules that you can add to Shuriken. The default modules are the basic properties, Emission, Shape of Emitter, and Renderer.
  • Currently, Unity's Particle Systems can only generate 2D particles. If you want to emit 3D particles, you'd have to write your own script. There are however many ways 2D particles can work in 3D space.

For extensive information on modules in Shuriken in Unity, visit this link: http://docs.unity3d.com/Documentation/Manual/ParticleSystemModules.html

Legacy Particles

  • Legacy Particle Systems in Unity require three components: an Emitter, a Particle Animator and a Particle Renderer.
  • To create a legacy particle system, you need to create an empty Game Object or attached the legacy particle system to can existing Game Object.
  • The different types of legacy emitters, animators, and renderer can be found at Component -> Particles -> Legacy. You usually want Ellipsoid Emitter, Particle Animator, and Particle Renderer.
  • There are many particle systems which are included in Unity's Standard Assets, like fire and smoke.
  • To import them, go to Assets -> Import Package -> Particles.

Emitters

Emitters are objects which, as the name implies, where particles are spawned from.

Emitters give particles their initial properties, such as:

  • Velocity - How fast and in what direction the particles move.
  • Size - How big the particles are.
  • Energy - How long a particle exists before it disappears. Otherwise known as their Lifetime.
  • Emission - How many particles spawn at one time.
  • Angular Velocity - At what speed will the individual particles spin.

Unity uses two different types of emitters: Ellipsoid and Mesh.

The two emitters are actually essentially the same; they're objects that tell the particles where to emit from. The difference is that the Ellipsoid Emitter is a spherical shaped emitter whose dimensions can be modified in the Inspector while the Mesh Emitter's shape is defined by whatever mesh is assigned.

Learn more about each emitter (and emitters in general) here:
http://docs.unity3d.com/Documentation/Components/class-EllipsoidParticleEmitter.html
http://unity3d.com/support/documentation/Components/class-MeshParticleEmitter.html

Learn how to create Mesh Particle Emitters here: http://docs.unity3d.com/Documentation/Manual/HOWTO-MeshParticleEmitter.html

Particle Animator

Particle Animators tell your particles how to behave after they come into existence.

Here you can modify the following:

  • Color Animation - What colors the particles cycle through. This also includes the Alpha (or transparency). If the particles are textured, then the only thing to note is the Alpha, which will allow you to fade your particles in and out.
  • Rotation Axis - What axis the particles orbit around. You can use this to make your particles move like in a vortex or tornado.
  • Size Grow - How big the particles become over the course of their lifetime.
  • Force - What world forces are applied to your particles. Use this for forces like gravity or wind.
  • Damping - The rate in which the particles slow down. Default is set to 1, which is no damping. Reduce the number to increase damping.

Learn more about Particle Animators here: http://docs.unity3d.com/Documentation/Components/class-ParticleAnimator.html

Particle Renderer

Particle Renderers define what the particles look like.

Here, you can assign any material you want to the particles. Typically, you would use Materials created specifically for particles, but it will accept any material.

By default, the it is set to Billboard (under the Stretch Particles property). This means that the particles will always face the camera. There are other settings available but Billboard is probably the one you want anyways.

UV Animation

  • You can animate your particle's textures by using a texture that is a series of images set in a grid (See Figure 1).
    Fig. 1, Animated Texture for Particles

Then, in UV Animation, set the number of frames that are in the x-axis (X Tile), the y-axis (Y Tile) and how many times the animation loops (Cycles). For the texture in Figure 1, X Tile would be set to 3 and Y Tile set to 2.

To make it so that the particles don't look like a bunch of squares, use the appropriate Shader for the material. Typically, the Particle Shaders will have you covered.

Read more on Particle Renderers here: http://docs.unity3d.com/Documentation/Components/class-ParticleRenderer.html

World Particle Collider

If you want the particles to collide with colliders in the scene, you add a World Particle Collider component to the particle system.

Select your particle system and go to Component->Particles->World Particle Collider.

Learn more here: http://docs.unity3d.com/Documentation/Components/class-WorldParticleCollider.html

Making Fire

In this tutorial, we will be making a very simple fire particle system. It might not look like what fire actually looks like but it will be passable.

  1. Create a Legacy Particle System with Ellipsoid Emitter, Particle Animator, and Particle Renderer
  2. Select the Particle System in the Hierarchy Panel. Under Min Size, enter 1.5. Under Max Size, Enter 2.5.
  3. Scroll down to Particle Animator and enter 0.5 in the Y-direction for Force.
  4. In Size Grow, enter -0.3.
  5. In the "Color Animation" section, pick colors top to bottom in this order: Orange, Orange, Yellow, Light Orange, Light Yellow.
  6. Hit play and enjoy.

Fire particle assets are also available as part of Unity's Standard Assets.

Trail Renderer

Trail Renderers are used to create effects like a weapon trail or ribbon-like effects.

Trail Renderers do not need to be attached to a Particle System and pretty much function as an independent Component. It is recommended that Trail Renderers are added to empty GameObjects and that GameObject is then parented (in other words, become part of that object's hierarchy) to whatever you wish to have a trail.

Trail Renderers are set in Billboard mode (always facing the camera) and this cannot be changed.

The Trail Renderer component is found under Component -> Particles -> Trail Renderer.

Find out more here: http://docs.unity3d.com/Documentation/Components/class-TrailRenderer.html

Line Renderer

Line Renderers are similar to Trail Renderers but they are static.

Find out more here: http://docs.unity3d.com/Documentation/Components/class-LineRenderer.html

Personal tools