Jump to content

Emitter Rotation Question


Titus
 Share

Recommended Posts

Hi,

I'm having some trouble with my emitter that is used as spray particles for a fire extinguisher.  I've set the emitX and emitY to position relative to the player's front arm and set the emitter.rotation = frontArm.rotation. The problem I'm having is that when the arm rotates the particle's emit location is moved. I've attached some screenshots and code to show what I mean. I'm sure it is something simple that I'm missing but I've searched on the forums for quite a while and can't seem to find a solution. Any help would be appreciated.

FireSim.test = {


	create: function()
	{

    this.game.stage.backgroundColor = "#d36a6a";
	this.waterSpray = this.game.add.emitter(0, 0);// (x, y, max particles)
	this.waterSpray.makeParticles('whiteParticle', '', 5000, true, false);
    this.waterSpray.maxParticleScale = 5;
    this.waterSpray.minParticleScale = 1;
    this.waterSpray.flow(1000, 100, 50, -1, false);
	this.waterSpray.minParticleSpeed.setTo(400);
	this.waterSpray.maxParticleSpeed.setTo(800);
	this.waterSpray.setYSpeed(-30, 30);
	this.waterSpray.gravity = 0;
	this.frontArm = this.game.add.sprite(150, 100, 'frontArm5');

},

update: function()
{

  if(this.game.physics.arcade.angleToPointer(this.frontArm.world) < 1)
  //only move the arms towards the mouse angle if it is less than 1. This prevents erratic 
  movement when the mouse pointer is positioned behind the player
  {
    this.frontArm.rotation = this.game.physics.arcade.angleToPointer(this.frontArm.world);
  }

	this.waterSpray.emitX = this.frontArm.world.x + 270;
    this.waterSpray.emitY = this.frontArm.world.y + 160;
	this.waterSpray.rotation = this.frontArm.rotation;

  	if (this.game.input.activePointer.isDown)
    {
  		this.waterSpray.on = true;
   	}
    else
    {
   		this.waterSpray.on = false;
   	}


	},
};

 

1.png

2.png

3.png

Link to comment
Share on other sites

@samme If I do that then the spray will always go directly forward, even if the arm is aiming up/down. I've more or less achieved what I wanted by placing a sprite with a null texture right at the end of the nozel of the extinguisher and then added the particle as addChild() of the frontArm sprite. Then in the update I have emiiter.emitX/Y = this.particle.world.x/y. This makes it so the spray always starts at the end of the nozel but still the spray always shoots directly to the right, even when the nozel is being pointed up or down. Any other suggestions?

Link to comment
Share on other sites

@samme Thank you, that's exactly what I needed. I'm still not sure why setting emitter.rotation/angle == frontArm.rotation/angle in the update caused the emit point to move. I'm guessing the actual emitter is a rectangle with an anchor of 0,0 and it was updating the rotation/angle of that whereas setAngle() is updating the actual emit locations angle. Appreciate the help regardless!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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