Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions get time at a value

  • get time at a value

    Posted by Amestane Tindi on January 7, 2015 at 8:43 pm

    Hi,
    I know how to get a value at a time, but I want to get the time at a certain value, I have a layer A that has the scale sized from 0 to 100% by a sampleImage function from layer B, and I want it to fade out after it get to 100% scale, so I need to have the time where it happen(let’s call this time value “st”) to be able to do to opacity “100-(st-time)”, example : A reach 100 scale at 50, so at this moment: opacity = 100-(50-50) = 100, and the more the time goes after that that more the A fade out, 100-50-60 ….

    Thank you.

    Regards,
    Amstane.

    Alborz Riazi replied 1 month ago 5 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    January 7, 2015 at 11:18 pm

    The best you can do is create a frame-by-frame loop that uses valueAtTime() to find the frame where the value reaches the threshold. You can start at the current frame and go backwards to find the most recent occurrence, or you can start at the earliest frame and go forwards to find the first occurrence. In either case you need to have logic to handle the possibility that it hasn’t happened yet.

    Dan

  • Amestane Tindi

    January 8, 2015 at 1:11 am

    Hi,
    Thanks Dan for your quick response.
    However I can’t do that my, the animation that trigger the other is automatic, no key-frames, it use sample image to see when to start, and I want to trigger the decrease animation when this scale one finish.

    I’ll try to tell it other way.

    Is there a way to make a decrease animation other way than with x-time technique ?

    Thanks a lot.

    Amstane.

    Regards,
    Amstane.

  • Dan Ebberts

    January 8, 2015 at 1:20 am

    > the animation that trigger the other is automatic, no key-frames

    That shouldn’t matter (unless I completely misunderstand what you’ve trying to do).

    If you want to find the time when the scale hit 100% (%99.99 would probably be safer), valueAtTime() is the way to do it. The idea is really similar to this:

    https://www.motionscript.com/design-guide/audio-trigger.html

    Dan

  • Amestane Tindi

    January 8, 2015 at 1:51 am

    I’ve found a temporarily solution, (below)
    But I’ll defiantly check yours tomorrow, seems complicated right now, but I’ll look deep into it.

    I used the scale animation reach 100% at 0.9 instead of 1 and kept the 0.1 for the glow effect that I’m applying on the layer.

    Amstane

    s=thisComp.layer("Animation Guide"); // the layer with the wipe animation that will be sampled
    sc=transform.scale[0]/100; // the scale depend already of the animation guide sampling from 0 to 0.9
    scL=linear(sc,0.5,1,0,1); // to have the glow start at scale 50
    v=s.sampleImage([transform.position[0],transform.position[1]],[.5, .5]); // sampling again nut from 0.9 to 1
    e=layer("ANIMATION").effect("Assembling Glow")(1)*scL; // control the glow max value with a slider
    ease(v[0],0.9,1,e,0) // While sampling goes from 0.9 to 1 the glow goes from e to 0

    Regards,
    Amstane.

  • Maria Ciszynska

    January 5, 2018 at 3:14 pm

    I know this thread is old but I have a similar problem and my knowledge of expressions is very basic. So any help greatly appreciated!

    I have a layer which goes from point A to point B, for which I want to create a 1 second overshoot of sorts, so that when it reaches B it moves back a bit.

    The movement is all automated with no keyframes as it’s linked to reveal of a text, so I only have value of B and value after overshoot. I would like to use an Ease expression on it, but I’m missing how to make it last 1 second and start after layer arrives at B. Any thoughts?

    Many Thanks,

    x=transform.xPosition;
    h=thisComp.layer("Dot").effect("Slider Control")("Slider");
    b=thisComp.layer("END OF TEXT").transform.position[0];
    o=thisComp.layer("OVERSHOOT").transform.position[0];
    minVal=g;
    maxVal=g+o;
    h1=(h==g);
    if (h<g) {
    x=h
    } else {
    easeOut(time,h1.time,(h1.time+1),minVal,maxVal)
    }

  • Jorge Diallo

    April 25, 2023 at 2:31 pm

    I had a similar problem: I’ve got text layer A with an opacity animator and a range selector. The start of the range selector has an expression, e.g. is a dynamic expression (depending on the length of the text). I’ve also got a text layer B with the same setup. The animation of the second animator is supposed to start 10 frames after the end of the animation of the first animator, e.g. the time at which the value reaches 100% for the first time.

    To do so, I needed an expression for the second animator to find that frame.

    Here’s the expression:

    var compLength = thisComp.duration / thisComp.frameDuration;
    var property = thisComp.layer("A").text.animator("X").selector("Y").start;
    var flag = false;
    var wantedFrame;
    
    for (var i = 0; i <= compLength; i++) {
        if (property.valueAtTime(i * thisComp.frameDuration) == 100)
        {flag = true; wantedFrame = i}
    
        if (flag == true) {break}
    }
    
    wantedFrame;

    The expression loops through every frame of the composition, starting at frame 0 and counting up to the very last frame (compLength). At every frame it looks at the value of the given property with .valueAtTime() and checks with an if-statement whether that value is equal to 100. If so, the flag variable is set true and the wantedFrame variable to that frame. At every iteration the for-loop looks with another if-statement whether the flag is true and if so, breaks out of the for-loop. The found frame (wantedFrame) is then returned.

    Replace property with whatever property you’re looking at and 100 with the value you’re looking for.

  • Alborz Riazi

    May 20, 2024 at 12:47 pm

    Thanks a million, this helped a lot.
    btw I had to tweak the code just a tad to compensate for the decimal values in my property values. it couldn’t find the frame

    var compLength = thisComp.duration / thisComp.frameDuration;
    var property = thisComp.layer("A").text.animator("X").selector("Y").start;
    var flag = false;
    var wantedFrame;
    
    for (var i = 0; i <= compLength; i++) {
        if (Math.round(property.valueAtTime(i * thisComp.frameDuration)) == 100)
        {flag = true; wantedFrame = i}
    
        if (flag == true) {break}
    }
    
    wantedFrame;

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