πŸ’¨ Particle System

The engine’s Particle System allows the creation of dynamic visual effects such as fire, smoke, sparks, rain or explosions. It is fully compatible with hierarchy, layers and visibility, and can work independently or as a child of any object.

βš™οΈ General Structure

A particle system is defined as an object of type ParticleSystem:

{
  "type": "ParticleSystem",
  "playOnStart": true,
  "looping": true,
  "simulationSpace": "local",
  "startDelay": 0,
  "destroyWhenDone": false,
  "particleData": { ... }
}

πŸŒͺ️ particleData Parameters

{
  "rate": 20,
  "life": 1.5,
  "speed": 100,
  "spread": 6.283,
  "color": "#ffaa00",
  "gravity": 0,
  "texture": "spark.png",
  "sizeMin": 4,
  "sizeMax": 12,
  "opacityMin": 0.5,
  "opacityMax": 1,
  "duration": 5
}
πŸ”Ή The engine automatically manages the internal particle list (particles[]). Each particle has its own position, velocity, life, size and opacity.

🧭 Simulation Modes

⏱️ System Lifecycle

⚠️ If looping is enabled, the destroyWhenDone parameter is ignored.

🧩 Hierarchy & Behaviour

A particle system can be the child of any object. When it is, it inherits position, rotation and scale like any other engine object.

🎨 Practical Examples

πŸ”₯ Fire (loop + local)

{
  "type": "ParticleSystem",
  "playOnStart": true,
  "looping": true,
  "simulationSpace": "local",
  "particleData": {
    "rate": 20,
    "life": 1.5,
    "speed": 50,
    "color": "#ff6600",
    "gravity": -30
  }
}

πŸ’₯ Explosion (no loop + destroyWhenDone)

{
  "type": "ParticleSystem",
  "playOnStart": true,
  "looping": false,
  "destroyWhenDone": true,
  "particleData": {
    "rate": 200,
    "life": 0.8,
    "speed": 300,
    "spread": 6.283,
    "color": "#ffaa00"
  }
}

🌧️ Rain (world + infinite loop)

{
  "type": "ParticleSystem",
  "simulationSpace": "world",
  "looping": true,
  "particleData": {
    "rate": 100,
    "speed": 400,
    "gravity": 600,
    "life": 2,
    "color": "#66aaff"
  }
}

πŸš€ Performance Tips

πŸ”§ Tip: Systems with low gravity and narrow spread produce smooth smoke-like effects. High values produce chaotic effects such as fire or explosions.

▢️ Code Control: PlayParticles() and StopParticles()

Besides editor configuration, particle systems can be controlled dynamically through scripts using two key functions:

PlayParticles(obj);
StopParticles(obj);

// Alternative usage by passing the object name
PlayParticles("Particle");
StopParticles("Particle");
πŸ’‘ Important: Both functions work whether the particle system is configured as a ParticleSystem object or inside components[] of another object.

πŸ”Ή Simple Example

let ps = getObjectByName("ExplosionFX");
PlayParticles(ps);

πŸ”Ή Stop Emission

StopParticles(getObjectByName("SmokeExit"));

πŸ”Ή Triggering After an Event (e.g., collision)

function OnCollision(obj, other) {
    let fx = getObjectByName("HitFX");
    PlayParticles(fx);
}

πŸ”Ή Delayed Play

Timer(1.2, () => {
  PlayParticles(getObjectByName("Sparks"));
});
βœ”οΈ PlayParticles always forces emission even if playOnStart is false.
βœ”οΈ StopParticles does not delete active particles; only stops new ones.
βœ”οΈ Fully compatible with looping, startDelay and destroyWhenDone.

πŸ“Œ Summary

- Particle systems support hierarchy, layers and visibility just like any other object.
- simulationSpace defines whether particles follow the emitter.
- destroyWhenDone removes the system when finished (no loop).
- Small textures and short lifetimes = best performance.