ForgeableSum Posted October 20, 2016 Share Posted October 20, 2016 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 More sharing options...
samme Posted October 20, 2016 Share Posted October 20, 2016 Phaser.Particle has a physics body: http://codepen.io/anon/pen/VKqZbm?editors=0010 Link to comment Share on other sites More sharing options...
damien leroux Posted July 10, 2017 Share Posted July 10, 2017 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.makeParticles('firework'); 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 More sharing options...
Recommended Posts