PDA

View Full Version : nParticles/ Instances - issue in expression


Phlok
01-06-2011, 10:23 AM
By this expression, I want to kill particles based on their y position (if lower than my locator "killZone" set lifespanPP to 0).


vector $locPos = <<killZone.translateX, killZone.translateY, killZone.translateZ>>; vector $ptclPos = nParticleShape1.position;
if($ptclPos.y < $locPos.y)
{
print("WTF??");
nParticleShape1.lifespanPP = 0;
}


Although the condition is fulfilled (some WTF?'s in the script editor window tell me so), the particles seem not to be killed at all (at least, the instanced geometry is still existing although being lower than the locator's position)

The expression above has done a fine job for me in several std particles jobs- so why isn't it working in this case? Am I missing something?

Thank you for any answers!

dizzyone
01-06-2011, 02:26 PM
Not sure how that has ever worked. position is local space IIRC. And I believe in this way it will be the center of all particles combined, although you shouldn't quote me on that.

I extended your print statement to give more feedback, and once the first particle goes below the locator in world space, this is what the print statement says:

WTF??
FIRST PARTICLE POS: .889105
LOCATOR Y POS: 0.911179414.
SHAPE.POS Y: -11.7591055
LIFESPANPP: 0


So lifespanPP doesn't seem to do anything here, and the nParticleShape1.position is giving a completely different position, as I guessed before, it must be local space, as -11 would be far below the locator, while this is not the case.


EDIT: My bad, forgot to set lifespan to lifespanPP only. So lifespanPP does work, but as the position variable isn't giving you a correct variable, it doesn't work as intended. I suggest you change the $ptclpos to something else, depending on the effect you want to create.

To get an accurate world space reading, I just took the position array of a single particle.

float $test[] = `getParticleAttr -at worldPosition nParticleShape1.pt[0]`;

so then $test[1] would be the translateY.

Phlok
01-06-2011, 02:58 PM
dank u well!

I forgot to set lifespanPP only, too.

Even though the results of the position value might not be accurate, somehow this works pretty well.

mandark1011
01-06-2011, 08:45 PM
this is how i do it and it works every time

expression
// creation and runtime
float $pos = worldPosition;
lifespanPP = 1000; (whatever number really)
//runtime
if ($pos.y <= loc.ty)
lifespanPP = 0;

name of your locator is loc and it is positioned where you want it to kill the particles

CGTalk Moderation
01-06-2011, 08:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.