Skip to main content
mart-martinlofqvist
Known Participant
December 20, 2016
Question

Move in x every [10] frames?

  • December 20, 2016
  • 1 reply
  • 3096 views

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

This topic has been closed for replies.

1 reply

UQg
Legend
December 20, 2016

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