Problem Moving Particle Emitter in TGE
by Balance686 · in Torque Developer Network · 04/02/2010 (6:19 pm) · 1 replies
Hi guys first off I'm new to TGE so if this sounds like a newb question it probably is. I'm making a demo level in a class and I have made a fountain that contains 3 particle emitters (one going down, one going up, the other radiating outward near the base) pictured here: http://i583.photobucket.com/albums/ss276/balance686/ZeroIdentity-fountaininaction2.jpg
I wrote a script to move the top emitter up and down at random intervals to simulate the bobbing of a real fountain. When I run the script I can see the emitter bobbing up and down in the world inspector mode but the problem is the particles do not follow with it. Instead they keep coming from their original position. Is there a way to fix this? Below is the script I wrote to achieve the motion:
//----------------------------------------------------------------------
// animfountain.cs
// This module translates the particle emitter fountainParticles1
// up and down the Z axis to simulate the behavior of a real fountain.
// written by David Brake for GSP340
//----------------------------------------------------------------------
function AnimShape(%shape)
{
if ( %shape $= "")
{
error("AnimShape needs 1 parameter.syntax:");
error("AnimShape(id);");
return;
}
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // first, get the current
%ly = getword(%xfrm,1); // transform values
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%rz = getword(%xfrm,5);
if ($isFirst) //is this first time running?
{
$lzOriginal = %lz; //store original z co-ordinate
$isFirst = false;
$target = (%lz + getRandom(1, 3));
}
if ($targetReached) //have we reached our target height?
{
if ($isRising) //were we rising?
{
$target = ($lzOriginal - getRandom(1, 3)); //new target will be below original z position
$isRising = false;
}
else //we were falling
{
$target = ($lzOriginal + getRandom(1, 3)); //new target will be above original z position
$isRising = true;
}
$targetReached = false;
}
//set new %lz
if ($isRising) //are we going up?
{
if (%lz < $target)
%lz += 0.1;
else
$targetReached = true;
}
else //we're going down
{
if (%lz > $target)
%lz -= 0.1;
else
$targetReached = true;
}
//perform translation
%shape.setTransform(%lx SPC %ly SPC %lz SPC
%rx SPC %ry SPC %rz SPC %rd);
schedule(20,0,AnimShape, %shape);
}
function startFountain(%shape)
{
if (%shape $= "" && isObject(%shape))
{
error("DoAnimTest requires 1 parameter.");
error("DoAnimTest syntax: DoAnimTest(shapeID);");
return;
}
$isFirst = true;
$isRising = true;
$targetReached = false;
AnimShape(%shape);
}
Any help would be GREATLY appreciated I have to submit this section on Sunday. Thanks!
I wrote a script to move the top emitter up and down at random intervals to simulate the bobbing of a real fountain. When I run the script I can see the emitter bobbing up and down in the world inspector mode but the problem is the particles do not follow with it. Instead they keep coming from their original position. Is there a way to fix this? Below is the script I wrote to achieve the motion:
//----------------------------------------------------------------------
// animfountain.cs
// This module translates the particle emitter fountainParticles1
// up and down the Z axis to simulate the behavior of a real fountain.
// written by David Brake for GSP340
//----------------------------------------------------------------------
function AnimShape(%shape)
{
if ( %shape $= "")
{
error("AnimShape needs 1 parameter.syntax:");
error("AnimShape(id);");
return;
}
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // first, get the current
%ly = getword(%xfrm,1); // transform values
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%rz = getword(%xfrm,5);
if ($isFirst) //is this first time running?
{
$lzOriginal = %lz; //store original z co-ordinate
$isFirst = false;
$target = (%lz + getRandom(1, 3));
}
if ($targetReached) //have we reached our target height?
{
if ($isRising) //were we rising?
{
$target = ($lzOriginal - getRandom(1, 3)); //new target will be below original z position
$isRising = false;
}
else //we were falling
{
$target = ($lzOriginal + getRandom(1, 3)); //new target will be above original z position
$isRising = true;
}
$targetReached = false;
}
//set new %lz
if ($isRising) //are we going up?
{
if (%lz < $target)
%lz += 0.1;
else
$targetReached = true;
}
else //we're going down
{
if (%lz > $target)
%lz -= 0.1;
else
$targetReached = true;
}
//perform translation
%shape.setTransform(%lx SPC %ly SPC %lz SPC
%rx SPC %ry SPC %rz SPC %rd);
schedule(20,0,AnimShape, %shape);
}
function startFountain(%shape)
{
if (%shape $= "" && isObject(%shape))
{
error("DoAnimTest requires 1 parameter.");
error("DoAnimTest syntax: DoAnimTest(shapeID);");
return;
}
$isFirst = true;
$isRising = true;
$targetReached = false;
AnimShape(%shape);
}
Any help would be GREATLY appreciated I have to submit this section on Sunday. Thanks!
Torque 3D Owner RealmX