- In an empty game scene add a GravityEngine.
- Drag the Star prefab into the scene.
- Using the Object menu add a Unity particle system and position it at X=+15.
- Attach a GravityParticles script to the particle system and press PLAY.
- The particles are detected by the gravity engine and evolved. They fall towards the star.
- 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.
- Open the DustBall script in an editor.
- DustBall implements the IGravityParticlesInit interface. This is described in the script documentation.
- Add a DustBall to the particle system in the scene.
- Change the particle system to emit long-lived particles in a one-time burst.
- Change lifetime to 999
- Set Looping to OFF
- Change start lifetime to 999
- Set initial velocity to 0
- Under Emission, set the rate to zero and configure a one time burst of 300 particles at time 0.
- Press PLAY.
- The ball of particles falls into the Star
- 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.