Tutorial 4 – Particles

  1. In an empty game scene add a GravityEngine.
  2. Drag the Star prefab into the scene.
  3. Using the Object menu add a Unity particle system and position it at X=+15.
  4. Attach a GravityParticles script to the particle system and press PLAY.
    1. The particles are detected by the gravity engine and evolved. They fall towards the star.
    2. The usual particle system controls can be used to control the shape, rate and velocity of the particles.

There are cases where it useful to have script control over the initial positions and velocities of the particles. One example is the DustRing script that enures all the particles are in orbit around a central body. A simpler illustrative example is DustBall.

  1. Open the DustBall script in an editor.
    1. DustBall implements the IGravityParticlesInit interface. This is described in the script documentation.
  2. Add a DustBall to the particle system in the scene.
  3. Change the particle system to emit long-lived particles in a one-time burst.
    1. Change lifetime to 999
    2. Set Looping to OFF
    3. Change start lifetime to 999
    4. Set initial velocity to 0
    5. Under Emission, set the rate to zero and configure a one time burst of 300 particles at time 0.
  4. Press PLAY.
    1. The ball of particles falls into the Star
    2. An initial velocity can be added to the ball via the DustBall inspector.

There are other init scripts for particles provided:

  • DustBox creates a 3D box of particles
  • DustRing (As described in the Overview) creates a ring of particles in orbit around a central object.