Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Access to the time and the duration of value.

  • Access to the time and the duration of value.

    Posted by Benoit Kergosien on June 21, 2014 at 9:28 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:

    seedRandom(1);
    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.

    Slider DIRECTION:

    delta = thisComp.frameDuration;
    tolerance = 0.7;
    mySquare=thisComp.layer("SQUARE");
    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:

    threshold=100;
    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;
    n++;
    }
    frame--
    }
    n

    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:

    number=thisComp.layer("SQUARE").effect("NUMBER")("Slider");
    i=number%2;
    if (i==0)
    {0}
    else
    {1};

    Right Arrow:

    number=thisComp.layer("SQUARE").effect("NUMBER")("Slider");
    i=number%2;
    if (i==0)
    {1}
    else
    {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.
    7655_squaredirection.aep.zip

    Any help would be gladly apreciated. Thanks in advance.

    Benoit Kergosien

    Benoit Kergosien replied 11 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    June 21, 2014 at 10:51 pm

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

    mySquare.position.velocityAtTime(t)[0]

    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.

    Dan

  • Benoit Kergosien

    June 21, 2014 at 11:45 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.

    7656_squaredirectionv2.aep.zip

    Benoit

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy