Copy link to clipboard
Copied
Hello,
I'm trying to simulate a pnuematic piston system for a tutorial at work. The system is a piston with 2 valves triggered by a controller and fed by seperate pressure regulators.
There are quite a few moving parts, but the important bit is I'm trying animate just the PSI sliders (effectively my speed) and Channel # checkboxes (on/off switches for each direction of motion).
I'm looking it the x position of the poston from one previous frame. When I trigger one of the check boxes it moves correctly for one frame and then freezes in that spot. If I key it on, then off, it goes back to its original position. I feel like looking for the previous frame value always just finds the original value.
Any suggestions?
Thanks!
var master = thisComp.layer("Master Control");
var pressureLeft = master.effect("PSI - Left")("Slider");
var pressureRight = master.effect("PSI - Right")("Slider") * 1.1;
var ch1 = master.effect("Channel 1")("Checkbox");
var ch2 = master.effect("Channel 2")("Checkbox");
var modifier = master.effect("Piston Speed Modifier")("Slider")
var previous = transform.xPosition.valueAtTime(time - thisComp.frameDuration);
if (ch1 == 0){
pressureLeft = 0
}
if (ch2 == 0){
pressureRight = 0
}
var difference = pressureLeft - pressureRight;
var movement = previous + difference * modifier
clamp(movement , 1149.6 , 862.6)
I haven't tested this at all, but if you wanted a full-blown accumulator, that lets you animate all the controls, it would look something like this:
var master = thisComp.layer("Master Control");
var pressureLeft = master.effect("PSI - Left")("Slider");
var pressureRight = master.effect("PSI - Right")("Slider");
var ch1 = master.effect("Channel 1")("Checkbox");
var ch2 = master.effect("Channel 2")("Checkbox");
var modifier = master.effect("Piston Speed Modifier")("Slider");
t = inPoint;
acc
...
Copy link to clipboard
Copied
When an expression references the current, past, or future value of the property the expression is applied to, it gets the pre-expression value (i.e. the keyframed or static value of the property--as if the expression didn't exist). So if you need the value the expression calculated on the previous frame, you need to recreate that value. The difficulty in doing that varies, depending on exactly what you're trying to do and what you have to work with. It sounds like you might need to start at time = 0, and calculate all previous motion based on the keyframed values of your checkboxes and your slider settings. A little tricky to set up, if you're not used to doing it.
Copy link to clipboard
Copied
I haven't tested this at all, but if you wanted a full-blown accumulator, that lets you animate all the controls, it would look something like this:
var master = thisComp.layer("Master Control");
var pressureLeft = master.effect("PSI - Left")("Slider");
var pressureRight = master.effect("PSI - Right")("Slider");
var ch1 = master.effect("Channel 1")("Checkbox");
var ch2 = master.effect("Channel 2")("Checkbox");
var modifier = master.effect("Piston Speed Modifier")("Slider");
t = inPoint;
accum = 0;
while (t <= time){
pL = ch1.valueAtTime(t) ? pressureLeft.valueAtTime(t) : 0;
pR = ch2.valueAtTime(t) ? pressureRight.valueAtTime(t)*1.1 : 0;
accum += (pL - pR)*modifier.valueAtTime(t);
t += thisComp.frameDuration;
}
clamp(value + accum, 1149.6 , 862.6)
You could simplify things somewhat if your sliders are static.
Copy link to clipboard
Copied
Hey!
Just realized I never responded to this, but your code worked perfectly when I pasted it in.
Thanks!
-Josh