ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Cycling position values without using LoopOut

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Francis Anderson
Cycling position values without using LoopOut
on May 14, 2019 at 6:30:43 pm

Hey folks,

I'm animating several hundred layers and want to animate horizontal movement using expressions and no keyframing so that I can control speed and other parameters using a slider on a null object and not have to manually adjust hundreds of keyframes if the client asks for changes.

I'm animating a light sweep across these layers. I'm animating horizontal movement to the right by multiplying time by an interval set by a slider and adding that to value[0].

What I want is for value[0] to loop with no key frames. My intended solution is to take a range from anchor point-500 to anchor point+500, divide it by 1000 and round it to get an interval, and use an if()else() statement so that every time value[0] moves far enough to the right, the interval moves up by one and then subtract that 1000px range times the interval from [value[0], essentially putting it back where it started.

However, this solution is not working, or I am scripting it incorrectly.

Thoughts?

Here is my script as is:

seedRandom(index, true);
x=comp("MAIN COMP").layer("vfx CONTROLS").effect("sweep delay")("Slider");
delay=random(-x,x);
speed=(time*comp("MAIN COMP").layer("vfx CONTROLS").effect("sweep speed")("Slider"))-delay;
interval=Math.round((effect("CC Light Sweep")("Center")[0]-transform.anchorPoint[0]-500)/1000);
[transform.anchorPoint[0]-500+speed-interval,transform.anchorPoint[1]];


Return to posts index

Filip Vandueren
Re: Cycling position values without using LoopOut
on May 14, 2019 at 7:30:25 pm

Hi Francis,

a few things:
- don't use speed as a variable name, it's a reserved name (you can get the speed and velocity of animated properties).
- If you are applying this expression to the Center of the LightSweep, then you appear to be asking for the (previous ?) calculated value of this property while you're calculating it. Expressions don't work that way.

BUt I think you can simplify by just using a modulo ?

seedRandom(index, true);
x=comp("MAIN COMP").layer("vfx CONTROLS").effect("sweep delay")("Slider");
delay=random(-x,x);
sp=(time*comp("MAIN COMP").layer("vfx CONTROLS").effect("sweep speed")("Slider"))-delay;

transform.anchorPoint - [500,0] + [sp%1000,0];




Return to posts index

Francis Anderson
Re: Cycling position values without using LoopOut
on May 15, 2019 at 7:44:11 pm

Thank you Filip!I didn't realize speed is a reserved variable, I wonder now how many times I've struggled to get an expression working because of this oversight.

That solution didn't end up working out for me. But I did find the solution, by applying a randomized delay in the parameters of an ease() cycle.
Below is the code I ultimately wound up using.

seedRandom(index, true);
loopDuration = comp("abstract Background").layer("vfx CONTROLS").effect("sweep speed")("Slider");
DIF=random(-comp("abstract Background").layer("vfx CONTROLS").effect("sweep delay")("Slider"),comp("abstract Background").layer("vfx CONTROLS").effect("sweep delay")("Slider"));
t = time-loopDuration*Math.floor(time/loopDuration);
X=ease(t,DIF,DIF+loopDuration,0,1600);
range=700;
[transform.anchorPoint[0]-range+X,value[1]];


Return to posts index


Filip Vandueren
Re: Cycling position values without using LoopOut
on May 16, 2019 at 6:20:49 am

Great that you got it working.

A few tips:

The Line:
t = time-loopDuration*Math.floor(time/loopDuration);
Can be expressed as:
t=time%loopDuration;

And instead of:
DIF=random(-comp("abstract Background").layer("vfx CONTROLS").effect("sweep delay")("Slider"),comp("abstract Background").layer("vfx CONTROLS").effect("sweep delay")("Slider"));

This would be a bit more compact and legible:
DIF =random(-1,1) * comp("abstract Background").layer("vfx CONTROLS").effect("sweep delay")("Slider").value;

Note that it’s best practice to always add .value to explicitly get the value of a slider or property, even though After Effects’ pick whip never adds it.

Now, because of how your random is set up, DIF can be negative, but t will never be negative, so doesn’t that mess up some of the animations? Ease will get to do a part of its interpolation or is that intentional?



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]