05 May 2007, 11:36 PM
For a script you could look for a scriptJob solution. But it sounds like an expression for that attribute would work better for you. Just use something like:
if (frame == 0 )
pSphere1.translateX = 0;
pSphere1.translateX = pSphere1.translateX + 0.2;
You'd need the if (frame == 0 ) to reset your attribute to initial value. This will add 0.2 to translate X attribute each time the expression is executed, that is when frame changes. Thus this will also increment translateX if you'll scroll the time slider backwards. If that's an undesired behavior you could go with a "formula" like solution:
pSphere1.translateX = frame*0.2;
Which is the same as saying, for each new frame, add 0.2 to the translateX of the sphere.
Hope that helps :)
05 May 2007, 12:29 AM
Er, yeah, I did mean expression (it's all scripting in my head).
That's pretty close to what I want, but not quite. I need to be able to maintain the initial position that it starts off it is part of it, and the other part is I need the ability to rewind the thing. Here, I wrote out an explination of what I'm trying to do but then answered my own question by writting it out so never posted it. This is just the one part I'm trying to figure out still, but should help shed some light on the math I need back.
Let me know if this makes sense, because half way through this switched from an explination for a post to more my personal notes of what I need.
So I'm animating particles flowing down a curve using Maya curve flow effect.
My goal is to be able to adjust the speed of the particles flowing along it in animation.
The issue I run into now is when I animate the speed, by adjusting the lifeSpan of the particles, they backtrack back down the curve when I turn up the Lifespan to slow down the particles, and jump forward when I turn down the lifespan to speed them up. (Their life span is how long they take to get across the curve. A lifespan of one second will take one second or 30 frames to get from the begining to the end of the curve.)
This is best how I understand the curve flow is built, at least for the speed and follow of the curve.
When created Maya places locators evenly spaced out across the curve. The particles use those locators as goals to travel to.
Each one of those locators is pluged into a color ramp. The translate vectors are pluged into the rgb value of the ramp. When a particle is born, using it's age normalized, it runs a value of 0 to 1 across the ramp, 0 being the top of the ramp, 1 being the bottom. As it travels across the ramp it's hitting those locator values to go hit as goals. I beleive the ramp allows those vectors to be blended between each other to allow a smooth transition from goal to goal. In short, the lifespan of the particle is equivilant to the length of the ramp. The ramp has the locators spaced out across it, which are spaced out across the curve.
So from particle birth to particle death (lifespan) is the time range.
Time range is equivillant to the ramp.
The length of the ramp is equivillant to the length of the curve.
a life span of 1 is 1 second of life, which is 30 frames. That means it takes 30 even steps across the length of the curve.
If we're on frame 15 at this point, that's 50% of the ramp.
But, if we change the lifespan up to 2 at this point, and we're still on frame 15, we're now only at 25% of the lifespan, and thus 25% of the ramp.
The error that occurs now is the particle backtracks to be at the 25% mark of the ramp rather than staying at 50% and meerly adjusting the amount of steps it needs to take the rest of the way down the ramp.
Lifespan is run through the age normalized attribute. What ever the lifespan is age normalized will convert that range to a value between 0 and 1
So what I need is a script or equation that keeps track of the percentage the particle has traveled and doesn't let it go under that percentage.
It has to be made a way that the values of the range of the lifespan can gradualy change as well.
So maybe what I need is one attribute that just has the percentage the particle is currently at.
if the life span is 1, we're one frame 15, that means we're at a normalized age of 0.5 Hold on to 0.5
at a lifespan of 1, the percentage step we count up every frame is 0.0333333 or 1/30.
Now, if we want to slow down the particles, and up the lifespan to 2, lets ignore the percentage that would currently put the particles at but count the steps left it needs to take for that speed.
1/60 = 0.0166667
So now we could add 0.016667 every frame to our attribute that we have and that should add one every frame to give us the right speed.
How do we make a mel script that adds a number per a frame?
05 May 2007, 07:59 PM
I've anything, could somebody remind me what == and += mean again? I can't find any documentation that says, but I know I've read it some where before.
05 May 2007, 09:05 PM
if(frame == 0)
This means, if "frame" is equal to zero.
$value += 0.2
this is shorthand for $value = $value + 0.2.
05 May 2007, 03:24 PM
How would I write a script that would add the value of one attribute to another attribute per every frame?
Like say I have a value of 1 for an attribute and I want to add 0.5 to it every frame.
So the first frame the attribute value is 1.5
the second is 2
the third is 2.5, etc.
I know how to script it to add it once and change as the attributes change, but now how to get it to continuously add it.
it seems as easy as this :
$value = 1 + (frame/2);
05 May 2007, 03:24 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.