FORUMS: list search recent posts

Access to the time and the duration of value.

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Benoit Kergosien
Access to the time and the duration of value.
on Jun 21, 2014 at 9:28:56 pm
Last Edited By Benoit Kergosien on Jun 21, 2014 at 10:23:38 pm

Hi there,
despite a hunt of expressions in the forum ( thank you dear Dan Ebberts)
I can't achieve to access the duration of a value.

The short story:
My SQUARE is moving withtwo arrows on left and right side, i want their animations switch to on when the SQUARE moves in their direction
and when it changes in the opposite the arrows scale down in 2 seconds and the opposite arrow switch to on,etc...

No doubts that many parts of my following process is unificient so please correct me.

The long story:
A SQUARE is animated with a wiggle:

freq = 0.2;
amp = 300
loopTime = 5;
t = time % loopTime;
wiggle1 = wiggle(freq, amp, 1, 0.5, t);
wiggle2 = wiggle(freq, amp, 1, 0.5, t - loopTime);
ease(t, 0, loopTime, wiggle1, wiggle2)

Two slider control are applied to the square with an
expression to determine changes in the direction of the SQUARE.


delta = thisComp.frameDuration;
tolerance = 0.7;
v1 = mySquare.position.velocity;
angle1 = Math.atan2(v1[1],v1[0]);
v2 = mySquare.position.velocityAtTime(time-delta);
angle2 = Math.atan2(v2[1],v2[0]);

if (Math.abs(angle1 - angle2) > tolerance) 0 else 100;

Slider NUMBER:

direction= effect("DIRECTION")("Slider");
above = false;
frame = Math.round(time / thisComp.frameDuration);
n = 0;
while (frame >= 0){
t = frame * thisComp.frameDuration;
if (above){
if (direction.valueAtTime(t) < threshold){
above = false;

}else if (direction.valueAtTime(t) >= threshold){
above = true;

Two Compositions: Left Arrow and Rigth Arrow are parented to the SQUARE.

I want the Arrow scale in 0 to 20 when the direction changes for the first time
then scale out 20 to 0 with a decay of 2 seconds when the direction changes again and so on.

But I don't achieve to determine the time of this change in the direction.

In addition when the direction occurs i would remap the time to synchronize the Arrow's animation
(depending wether the direction goes to the left or to the right)

At the moment i accomplish that with an expression on the Time Remap:
Left Arrow:

if (i==0)

Right Arrow:

if (i==0)

But once again i dunno how to access to the time and the duration of direction changes for example between the 4th and the 5th
of my slider "NUMBER". My Arrow animation stays fixed. :(

I join the project if someone wants to take a look it would be easier to understand.

Any help would be gladly apreciated. Thanks in advance.

Benoit Kergosien

Return to posts index

Dan Ebberts
Re: Access to the time and the duration of value.
on Jun 21, 2014 at 10:51:43 pm

For the direction, I think you just need to monitor the x component of the square layer's velocity:


if it's positive, the square is/was moving to the right, negative to the left.

From there it gets complicated, even if you make the simplifying assumption that the scale-up and scale-down animations are never triggered while the other animation is in progress. You need a more complicated threshold detector that starts at the current frame and goes backwards to find the most recent threshold crossing (in either direction). Whether it was a positive-to-negative or negative-to-positive transition determines whether you run the scale-up or scale-down animation (you would do the opposite for the other arrow).

Anyway, tricky, but not impossible.


Return to posts index

Benoit Kergosien
Re: Access to the time and the duration of value.
on Jun 21, 2014 at 11:45:08 pm

Hey Dan!

Thanks for your consideration.

I simplify my code as you suggest but for the complicated treshold i'm a bit overwhelmed. I understand what you point but to transform the idea into an expression I'm afraid that I need more help.

I updated my project file if you have time to take a look.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 All Rights Reserved