Creating and mounting particle emitters in script
by Yost Engineering · in Technical Issues · 10/31/2007 (2:07 pm) · 10 replies
I have a dts object "Portal.dts" with 4 mount nodes, I want to be able to create the object in torque and have 4 particle emitters automatically mounted to it.
I have this script as an outline, but I know it is incorrect
I am unsure of how to actually dynamically create and instance of the Particle emitter in script, and I'm not sure if my code for mounting it is correct either. Also when I am actually modelling the object, should I parent the mount nodes to detail32 or to the object itself?
Any answers are appreciated!
I have this script as an outline, but I know it is incorrect
datablock StaticShapeData(Portal)
{
category = "AnimatedObjects";
shapeFile = "~/data/shapes/Portal/Portal.dts";
type = "Portal";
};
function Portal::onAdd(%this, %obj)
{
%emitter1 = PortalParticleEmitter();
%emitter2 = PortalParticleEmitter();
%emitter3 = PortalParticleEmitter();
%emitter4 = PortalParticleEmitter();
%obj.mountObject(%emitter1,mount0);
%obj.mountObject(%emitter2,mount1);
%obj.mountObject(%emitter3,mount2);
%obj.mountObject(%emitter4,mount3);
}
datablock ParticleEmitterData(PortalParticleEmitter)
{
.... existing particle script...
}I am unsure of how to actually dynamically create and instance of the Particle emitter in script, and I'm not sure if my code for mounting it is correct either. Also when I am actually modelling the object, should I parent the mount nodes to detail32 or to the object itself?
Any answers are appreciated!
#2
11/02/2007 (12:43 am)
That helps a little, however I am still very confused, there is a lot of code in there, can someone point out to me the snippets that actually create the particle emitters and what code is used to mount them to the specific named mount nodes in the dts file?
#3
11/02/2007 (3:56 am)
Study it. It's the only way. Get Torsion if you don't already have it--that'll help significantly.
#4
I tried this
%emitter1 = new(PortalParticleEmitter)();
but it tells me that it cannot be instantiated because its a "non-conobject class"
thanks.
11/02/2007 (2:14 pm)
I just don't understand it, can someone please just tell me what the code is for instantiating a new particle emitter within the script?I tried this
%emitter1 = new(PortalParticleEmitter)();
but it tells me that it cannot be instantiated because its a "non-conobject class"
thanks.
#5
11/02/2007 (2:20 pm)
That issue is a long term bugaboo in Torque. Unfortunately, every time I get it I have to just move things around until it works. I believe it has to do with the order in which the datablocks (and their dependencies) are declared.
#6
I appreciate your help and quick replies Lee!
11/02/2007 (3:07 pm)
Hmmm, I changed the order that my scripts are loading to make sure the Portal.cs is getting loaded last (after the particles). I also switched to the CampFireEmitter to make sure it wasn't something in my emitter code but I am still getting the "non-conobject" error. Here is the contents of Portal.cs at the moment:datablock StaticShapeData(Portal)
{
category = "AnimatedObjects";
shapeFile = "~/data/shapes/Portal/Portal.dts";
type = "Portal";
};
function Portal::onAdd(%this, %obj)
{
%emitter1 = new ParticleEmitter()
{
datablock = CampFireEmitter;
};
%emitter2 = new ParticleEmitter()
{
datablock = CampFireEmitter;
};
%emitter3 = new ParticleEmitter()
{
datablock = CampFireEmitter;
};
%emitter4 = new ParticleEmitter()
{
datablock = CampFireEmitter;
};
%obj.mountObject(%emitter1,mount0);
%obj.mountObject(%emitter2,mount1);
%obj.mountObject(%emitter3,mount2);
%obj.mountObject(%emitter4,mount3);
%obj.playThread(0,"Action");
}I appreciate your help and quick replies Lee!
#7
Please let me know if you discover the trick!
11/02/2007 (3:56 pm)
Unfortunately, I don't have a solid answer to this issue. It's plagued me for a long time. I'd love to know more certainly. It still might be useful to study my working jetpack code, look for patterns and such.Please let me know if you discover the trick!
#8
11/09/2007 (7:12 pm)
If you have the finances for it, get the AFX CoreTech content pack. ( http://www.garagegames.com/products/102/ ) If you need to do something ( Anything! ) with particles, especially mounted emitters, it will do it.
#9
then when it loads the shape it adds the emitter..
TomFeni
11/09/2007 (8:34 pm)
Heres what I have been doing, I just create it at worldbox center..function pipeSpinner::onAdd(%this,%obj)
{
%obj.playThread(0,"spin");
%obj.collideable = true;
%effect = new ParticleEmitterNode() {
position = vectorSub(%obj.getWorldBoxCenter(), "0 0 -5");
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "pipeSpinEmitterNode";
emitter = pipeSpinEmitter;
velocity = "1";
};
%obj.myEffect = %effect;
}then when it loads the shape it adds the emitter..
TomFeni
#10
datablock StaticShapeData(Portal)
{ category = "AnimatedObjects";
shapeFile = "~/data/shapes/Portal/Portal.dts";
type = "Portal";};
function Portal::onAdd(%this, %obj)
{
%emitter1 = new ParticleEmitter()
{ datablock = CampFireEmitter;
};
}
i had to edit it a little bit (copy and paste didnt hold the format). anyway, the datablock for CampFireEmitter needs to be created BEFORE anything that uses it. if CampFireEmitter uses a datablock inside of it that datablock needs to be created BEFORE CampFireEmitter.
its pretty simple. lets say i want to make some french toast. i need to heat the pan. crack the egg, dip the bread in the egg, then put it in the heated frying pan.
what you're trying to do looks like. crack the egg, heat the pan, dip the bread in the egg, then cook it in the frying pan. you have a few steps out of order thats all.
11/26/2007 (12:46 pm)
You need to put your code in a certain order. so lets take what you have heredatablock StaticShapeData(Portal)
{ category = "AnimatedObjects";
shapeFile = "~/data/shapes/Portal/Portal.dts";
type = "Portal";};
function Portal::onAdd(%this, %obj)
{
%emitter1 = new ParticleEmitter()
{ datablock = CampFireEmitter;
};
}
i had to edit it a little bit (copy and paste didnt hold the format). anyway, the datablock for CampFireEmitter needs to be created BEFORE anything that uses it. if CampFireEmitter uses a datablock inside of it that datablock needs to be created BEFORE CampFireEmitter.
its pretty simple. lets say i want to make some french toast. i need to heat the pan. crack the egg, dip the bread in the egg, then put it in the heated frying pan.
what you're trying to do looks like. crack the egg, heat the pan, dip the bread in the egg, then cook it in the frying pan. you have a few steps out of order thats all.
Torque Owner Lee Latham
Default Studio Name
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8156
I use this in my game, and the script source is available in server/scripts/mountedparticle.cs. I use it for my jetpack trails. You can get my test version here:
www.singularityfps.com
That was convenient!