Copy link to clipboard
Copied
Hi!
Trying to figure out how out how to script this:
• Move an object forward in x every [45] frames the whole time of the comp. And no movement at all.
I tried doing this setup:
----------
length = Math.floor(thisComp.duration);
lengthFrames= timeToFrames(length);
cycle = lengthFrames/thisComp.layer("Null 2").effect("Value")("Slider");
tid = Math.floor(timeToFrames(time));
if (tid % cycle == 0) {
transform.xPosition +10;
}
----------
(I used a null layer with a slider for easier debugging and so I can change the value on the fly later.)
The equation results in 0 every 45th frame – which is good but the movement happens every frame. I can't figure out how to trigger a certain movement just on that occasion and nothing else!
Somebody in here that has a suggestion how to solve this?
Best
Copy link to clipboard
Copied
Maybe this works:
tStart = inPoint;
period = thisComp.layer("Null 2").effect("Value")("Slider").value; // assumed: frames
DX = 10; // pixels
period *= thisComp.frameDuration;
t = time-tStart;
if (t<=0){value;}else{
nStep = Math.floor(t/period);
value + nStep * DX;
};
It is assumed that dimensions are separated (because it looks to be so from your expression).
If not, you should replace: value + nStep * DX;
by: [value[0] + nStep * DX, value[1]];
And the slider is assumed to give the time period in frame units.
If seconds, comment out the line period *= thisComp.frameDuration;
Xavier
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more