Jump to content

Control rotation of particles from particle emitter


Recommended Posts

I know how to set the rotations of particles to something random or arbitrary, but how does one set the rotation based on other variables?

For example, what if I want to explode a bunch of particles from a point and have the rotation of each particle determined by the velocity on each particle... imagine you have a confetti image that is a straight line with the angle set to 0 (the line goes from left to right). When the confetti emits, you want to rotate the confetti based on its x/y velocity set by the emitter. These problems would be easy to solve if I had access to a phaser physics body, but the particle nor the particle sprite have bodies. Thus, I don't even know how to read the velocity of each particle by putting a listener on the emitter.  

Link to comment
Share on other sites

  • 8 months later...

This is an old post but in case it helps anyone, I share the code that can control the particle rotation. In this example, the particle direction go from top to down when falling enough to trigger the particle rotation:

particlesEmitter.forEachAlive((particle) => {
	if (particle.body.velocity.y > 100) {
		if (particle.animations.sprite.rotation >= 0 && particle.animations.sprite.rotation < Math.PI) {
			particle.animations.sprite.rotation += Math.PI / 40;
			if (particle.animations.sprite.rotation > Math.PI) {
				particle.animations.sprite.rotation = Math.PI;

Here was my emitter config:

const particlesEmitter = game.add.emitter(0, 0, 30);
particlesEmitter.gravity = 300;
particlesEmitter.setXSpeed(0, 0);
particlesEmitter.setYSpeed(-480, -660);
particlesEmitter.minRotation = 0;
particlesEmitter.maxRotation = 0;
fireworksEmitter.lifespan = 5000;

Version: v2.6.2 "Kore Springs"

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...