Particle attractors

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.

16 Likes

Great feature!

1 Like

It’s interesting, it’s a shame that webgpu does not support it.

Amazing feature! I’ve tweaked the example… https://playground.babylonjs.com/#DEZ79M#43

5 Likes

it works with WebGPU but you have to use ParticleSystem and not GPUParticleSystem :slight_smile:

1 Like

Ah okay, I understand better. It’s cool then.

1 Like

Awesome feature - thanks so much @Deltakosh! I was trying to make a tire smoke/burnout effect recently, and this makes it so much easier to get natural looking particle movement -

9 Likes

Oh excellent idea!!! Love the use for the smoke direction!