Game Development Community

moving particleEmitterNodes?

by Stefan Beffy Moises · in Torque Game Engine · 07/26/2002 (5:24 pm) · 12 replies

hey there, I'm trying to move particleEmitterNodes without attaching them to any other Item, Weapon, etc.
In short, I do it this way:

commandToClient(%this.getControllingClient(), 'GenerateEmitterNode',%this);

...

function clientCmdGenerateEmitterNode(%client)
{
	 echo("clientCmdGenerateEmitterNode called!" SPC %client);
	 %client.trailEmitter = new ParticleEmitterNode() {
			position = %client.getTransform();
			rotation = "1 0 0 0";
			scale = "1 1 1";
			dataBlock = "LifestoneEmitterNode";
			emitter = "BlueSpellEmitter";
			velocity = "1";
	 };
   %client.trailSchedule = schedule(500,0,"updateTrail",%client);
}
function updateTrail(%client)
{
	 %client.trailEmitter.setTransform(%client.getTransform());
   %client.trailEmitter.setScale("1 1 1");
	 echo("updateTrail called" SPC %client.trailEmitter.getTransform());
   %client.trailSchedule = schedule(500,0,"updateTrail",%client);
}

No, the echos are returning what I am expecting, the position/tranform of the node *seems* to be updated, but it doesn't move at all...
So it looks like the node isn't packed/unpacked and therefore "visually updated" at all...
any idea how to achieve this?
I'm wondering because you CAN move the nodes in the world editor, and it doesn't seem to do anything else than I do...
Thanks a lot!!!!

#1
07/27/2002 (1:49 am)
Btw., it didn't work "server-side", either... just in case you are wondering why I'm using "commandToClient" ...
#2
07/27/2002 (8:47 am)
Another approach: is it possible to attach the node to the player (or any other object) directly? I think Melv has done this with his fxLight... maybe I should have a look there... ;-)
#3
07/27/2002 (2:49 pm)
I'm not really too sure about this Stefan, as I only started working with the particle engine a couple of days ago. But from what I've been able to gather so far by reading the comments in the code, especially the ones for the foot puff emitters, it doesn't seem like you can actually move them. It appears the way to simulate it though, is to destroy the emitter and make a new one in a different place. Therefore if you want your player to have a particle trail, you would check to see if his position has changed, and if it has, you would destroy the last emitter you'd made and make a new one at his new location. This is how I make my emitters:

function MendwoundsImage::makeEmitter(%this, %obj)
{
%position = %obj.getWorldBoxCenter();

%emitter = new ParticleEmitterNode() {
position = %position;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultEmitterNode";
emitter = "FountainEmitter";
velocity = "1";
};
MissionCleanup.add( %emitter );
%this.parObject = %emitter;
}


I'm sorry I can't be more help right now. I'm still trying to figure this out myself. If I come up with anything else I'll let you know.
#4
07/27/2002 (3:12 pm)
Never Mind.
#5
07/27/2002 (3:17 pm)
Thanks Robert G.! Yep, this works... but there has to be a way to move these suckas... ;)
I would accept that they cannot be moved if it wasn't possible to move them in the mission editor ... but you actually *can* move them in the mission editor, and this is really bugging me - cause the code for the mission editor object movement seems to do exactly the same as I am doing... it simply calls "setTransform()" ... it doesn't set any mask bits or dirty flags, etc. - at least I can't find anything...
I've also tried to add a "PositionMask" bit flag to the class, and I was reading and writing it in pack/unpackUpdate and I've also redefined "setTransform()" there (and set the bit in the function), but to no avail... :-(
Very strange indeed... but thanks for your help!!
#6
07/27/2002 (10:18 pm)
Well emitters are purely client side. So if your creating the emitters on the server than there is your problem. Emitters are not meant to be passed through the server because it's just really not necessary.

To get around this you can do like projectiles. Attach the emitter to an object that does move for server and client side. This means the client can update the position of the emitter by determining the position of the object it is attached to.
#7
07/28/2002 (6:36 am)
Ok Stefan, get ready for a whole lotta code. In my game the player casts a heal and I want some pretty particle effects to spew out of him, so this is in my onTrigger for the heal spell:

%this.makeEmitter(%obj);
       schedule(5, 0, "remakeEmitter", %this, %obj);
      schedule(2500, 0, "deleteEmitter", %this);

Then these are the fuctions

function MendwoundsImage::makeEmitter(%this, %obj)
{
     echo ( "Gosh ma'am, you got real purty lips");
    %position = %obj.getWorldBoxCenter();

	%emitter =	new ParticleEmitterNode() {
			position = %position;
			rotation = "1 0 0 0";
			scale = "1 1 1";
			dataBlock = "defaultEmitterNode";
			emitter = "FountainEmitter";
			velocity = "1";
		};
	MissionCleanup.add( %emitter );
	%this.parObject = %emitter;
}

function deleteEmitter(%this)
{
      %curr = %this.parObject;
      if( %curr )
      {
          echo( "Play dead, good boy");
          %curr.delete();
      }
      %this.parObject = false;
}

function remakeEmitter(%this, %obj)
{
    echo( "I'm working");
    %curr =  %this.parObject;
    %position = %obj.getWorldBoxCenter();
    %emitterPos = %curr.position;
    
    if(%curr)
    {
       schedule(5, 0, "remakeEmitter", %this, %obj);
    }
    else
    {
       echo( "Touch me again and I'll kill you");
       return;
    }
    
    if( %position == %emitterPos )
    {
        %moved = false;
        echo( "I'm not moving an inch!");
    }
    else
    {
        %moved = true;
        echo( "Catch me if you can!" );
    }
    
    if(!%moved)
    {
        echo( "Screw you guys, I'm going home" );
        return;
    }

    else
    {
        echo( "Booya granma!" );
        if(%curr) //there is an object already
    	{
            echo ( "Take out the trash");
            %curr.delete();
    		%this.parObject = false;
    	}

    	%this.makeEmitter(%obj);
     }
}

If you pass it the player as %obj, you'll get a nice little trail. I'm sure it's horribly inefficient and I'm absolutely positive that there are probably 30 better ways to do it, but it's a start. Good luck and if you find a better way to do it please let me know.
#8
07/28/2002 (6:39 am)
DOH!!! I forgot to take out my testing-purposes echoes and it won't let me edit my post for some reason. How embarassing, the whole world gets to see my dorky comments, hehe.
#9
07/28/2002 (11:42 am)
Small bug fix. If you have an emitter already going and you make a second one it won't delete the first one, so to ensure that there aren't two emitters up at once, change:


%this.makeEmitter(%obj);
      schedule(5, 0, "remakeEmitter", %this, %obj);
      schedule(800, 0, "deleteEmitter", %this);


to this:

if(!%this.parObject)
      {
           %this.makeEmitter(%obj);
      }
      schedule(5, 0, "remakeEmitter", %this, %obj);
      schedule(800, 0, "deleteEmitter", %this);


This will ensure that only 1 emitter exists at a time.
#10
07/29/2002 (1:02 am)
Hey Robert, thanks a lot!!
But I've decided to use a workaround instead... I've defined a custom Item type, which emitts particles, so it's like a "projectile" or something... it has an empty dts, so that you don't see anything of it, and there are only particles... and now you can mount the item to the player (just used the "WeaponMount" node because every player shape will have it...) so that it moves with the player and emitts its particles... works like a charm! :)
#11
07/29/2002 (6:40 am)
Well if I'd known you wanted the easy and obvious solution.......hehe
#12
09/28/2003 (3:25 pm)
Hello,

Was trying to do the same a few weeks ago and basically came up with what Robert did - it works but is not too elegeant - I am curious if Stefan, you could post what you did in detail - since that seems like a much better solution ineed

thanx
C