pixijs / particle-emitter

A particle system for PixiJS
http://pixijs.io/particle-emitter/docs
MIT License
786 stars 124 forks source link

Particle Attraction #119

Closed c-andrews closed 2 years ago

c-andrews commented 4 years ago

Hi, Sorry this isn't an issue, I wanted to ask if there was a way to make the particles become attracted to a particular point?

What i am trying to do it have a burst of particles and then have them attracted to a particular point.

Any advise would be greatly appreciated.

andrewstart commented 4 years ago

Attracted to an arbitrary point in your world-space or a ring of particles being pulled to the center of the circle that they spawn around? The former would require you to create your own custom Particle sub-class, the latter can be done with a combination of the ring spawn type and a starting rotation of 180 degrees (or a little off that if you want to imply a little bit of twist). If you want a strong curve, like circling a drain, then you could use a PathParticle with something like a sin() curve to give a strong inwards curve.

c-andrews commented 4 years ago

Yes sorry I would like the particles to be attracted to a point (x,y) in the world.

So from my understanding I would extend the Particle class for example a AttractedParticle, then make my calculations in the update to pull the particle towards a point?

Do i just set the new to the emitter.particleConstructor?

Thanks

andrewstart commented 4 years ago

Yeah, you'd make your calculations in the update. I'd use PathParticle as an example, in particular noting where it sets this._doNormalMovement so that the base particle movement doesn't interfere with your attraction. To use it, at some point during your initalization/configuration of your emitter, set myEmitter.particleConstructor = AttractedParticle; and that should do it.

andrewstart commented 2 years ago

Making custom movement is much easier with behaviors in release 5.0.0.