Scripting - Attaching a normal runtime created particle emitter to a object.

LF
Freeware Edition
Joined 27 April 2009
02 March 2010 18:41:08
Hello everyone. I am facing another silly scripting problem but this time with attaching a emitter that is generated at runtime to another object that is generated at runtime.
I have this script:
function onClick()
{
    var objectAdd =scenes.Document.objectAdd("FeatherEmitter_"+system.timer, "ParticleEmitterHolder", new Vector(0,3,0));
    objectAdd.scale = new Vector(0.251, 0.251, 0.251);//Scale the object the way you want
    objectAdd.pos = scenes.Document.objects.PosPoint.pos;
    objectAdd.pos.y = scenes.Document.script.MousePosPointUpVector;//Add the object at the cursor position
    system.script.ObjectListCountNumber += 1;
    var objectEmitter =  scenes.Document.objectAdd("FeatherTrueEmitter", "emitter");
    objectEmitter.pos = objectAdd.pos;
    //objectEmitter.attach(objectAdd, "", true, false, false); I am 100% sure that this line is wrong somewhere.
    objectEmitter.emitter.active = true;
    objectEmitter.emitter.direction.y = "90";
    objectEmitter.emitter.directionSpread = "360";
    objectEmitter.emitter.particleType = "Feather";
    objectEmitter.emitter.frequency = 6;
    objectEmitter.emitter.speed = 0.4;
    objectEmitter.emitter.directionSpread = 250;
}
It took me a while to figure out how to create the emitter and make it work properly but when I create another object the emitter isn't attached to the object.
LF
Freeware Edition
Joined 27 April 2009
02 March 2010 18:47:39
Everything works except the attach part. I tested it a hundred times to see wheres the bug, well the object.attach line is the problem.
Farad77
Non-Commercial Pro Edition
Joined 05 September 2008
02 March 2010 19:02:59
Can you post a doc? i may look at it to help, as it is i'm not quite sure of what could be wrong.
If you can't post it, try to play with the boolean true,true,true.
Or try to addit to some subgroup of ParticleEmitterHolder if there's any.
BUnzaga
Commercial Pro Edition
Joined 07 June 2006
03 March 2010 05:21:21
objectAdd is an object reference, not an object id.
var wantPos = scenes.Document.objects.PosPoint.pos;
wantPos.y=scenes.Document.script.MousePosPointUpVector; // I think you need a float here, not a vector...
var objectAdd = scenes.Document.objectAdd("FeatherEmitter_"+system.timer, // object name
  "ParticleEmitterHolder", // object mesh
  wantPos, // object pos
  null// default (0,0,0)
  new Vector(.251, .251, .251)); // scale

var objEmitter = scene.Document.objectAdd("FeatherTrueEmitter", "emitter", objectAdd.pos);
objEmitter.attach(objectAdd.id, "", truefalsefalse);
// yadda yadda yadda
I would suggest NOT using the system timer if you plan to create more than one of these in an instant. The reason is that you can create several things in one update cycle, which will all have the same system time IE the same ID. You could use a counter 'objCounter'.

objectAdd...  "FeatherEmitter_"+(objCounter++);

I also will usually use the object id that I am attaching to, since they have to be unique usually.
var objEmitter = ... "feather_emitter_"+objectAdd.id ...

Now you know what object it is attached to, and that its a feather emitter. If you need to for some reason, you could object.id.slice(("feather_emitter_").length) and now you have the object ID of the parent.

Sorry, this is a lot more than you asked for. Use what you want, disregard the rest.
LF
Freeware Edition
Joined 27 April 2009
03 March 2010 12:53:04
objEmitter.attach(objectAdd.id, "", true, false, false); This line solved my problem thank you BUnzaga! You got your name in the credits

If you'd like to post to this forum, just create an account on the website, or login with your existing details.

When posting to a forum, you can use limited HTML tags:- 'a' for links, 'b' for bold, 'i' for italic and 'script' to encase a block of DX Studio script.  All tags must be properly closed. e.g. <script>var i=1;</script>

Note: If there are any offensive comments in this topic, please let us know straight away at . Always follow the forum rules.