PDA

View Full Version : How do I make a % of particles die at a certain age?


Mayan-Seraph
04-21-2006, 01:02 AM
Nowhere in Maya can I find a setting that allows me to make a certain percentage of all particles in a cloud that reach a certain age die (Like: If particle age is X, then particle has Y chance to die)

Is it possible to do this with a simple MEL script?

spillway
04-21-2006, 02:22 AM
You need a couple of "if" statements.

Something like this will do what you need it to do:

float $particleAge = particleShape1.age;

if ($particleAge > 5)
{
float $random = rand(0,100);
if ($random < 50)
{
particleShape1.lifespanPP=0;
}
}

So this will kill 50% of your particles if they are older than 5 seconds. Substitute in the values you need for age, percentage and particleShape, and add as a runtime expression to your lifespanPP attribute.
Also you should double check that your Lifespan mode in the particleShape Attributes is set to lifespanPP only. Maya has a funny habit of changing that to constant and making it look like the script doesn't work.

Woo Hoo. I am on the last day of a mel scripting short course and i can answer your question, so i'm stoked!

Mayan-Seraph
04-21-2006, 03:38 PM
It works! Thank you very much. This has convinced me that learning MEL is important. There must be tons of other very cool stuff to do with it...

Mayan-Seraph
04-21-2006, 06:56 PM
Hmm.. it appears it does not do what I looked for afterall. This script takes ALL particles older than age X, and kills Y percent of those. This means that after a certain age the stream gets thinner and thinner, because once Y percent of a certain batch got killed, Y percent of the survivors gets killed the next frame, and so forth...

I've managed to solve this by letting Maya kill all particles within a range like "if A < Age < B"...

Now I need to solve another problem. How do I tell Maya to give the particles a certain radius as a function of particle age? Like: Particle radius = 2*particleage^2

spillway
04-21-2006, 10:04 PM
Yes MEL scripting is very useful. Having just spent the last week learning it i feel pretty much like maya is my bitch now...LOL.

Anyway pack to the problem... you want the particles to grow or shrink as they get older right?

You dont even need a script for this. You just need to add a dynamic attribut for radiusPP and map a ramp to it. As long as you have some randomness in the lifespanPP you will get a suitable result i would say.

Mayan-Seraph
04-22-2006, 11:44 AM
Well I do want to take control through MEL because the ramp looks at the age relative to the lifespan of each particle. By using a MEL expression I can actually control the lifespan as a function of the absolute age.

I've managed to do this finally... Your little script is very adaptable and teached me a lot. This is what it currently looks like:

{
if (MissleTrail.age <1)
{
MissleTrail.radiusPP = sqrt(MissleTrail.age);
}
if (MissleTrail.age >= 1)
{
MissleTrail.radiusPP = 1.5;
}
}

{
if (0.1 > MissleTrail.age > 0)
{
float $random = rand(0,100);
if ($random <= 95)
{
MissleTrail.lifespanPP=(1+rand(-0.4,0.2));
}
if ($random > 95)
{
MissleTrail.lifespanPP=4;
}
}
}

spillway
04-22-2006, 08:54 PM
Good stuff, seems like you're getting the hang of it.

CGTalk Moderation
04-22-2006, 08:54 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.