Hey all! I’m happy to announce a new feature added for the CPU particles: The attractors.
Starting from Babylon.js v8.4, you can create add gravity attractors to your particle system.
Note: Attractors are NOT supported in GPUParticleSystem.
Here is a complete example to try: Attractor demo | Babylon.js Playground
How To Use Attractors
An attractor is a simple class that contains a position (Vector3) and a strength.
Setting the strength to a negative value will create a repulsor.
// Attractor
const attractor = new BABYLON.Attractor();
attractor.strength = 2;
attractor.position = new BABYLON.Vector3(0, 1, -1);
particleSystem.addAttractor(attractor);
You can change the position or the strength of an attractor at any time.
To remove an attractor, simply call particleSystem.removeAttractor(attractor);
Finally, if you want to get a readonly list of attractors attached to a particle system, you can simply use the particleSystem.attractors property.