Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger linear Interpolation

  • Trigger linear Interpolation

    Posted by Brian Swarthout on June 21, 2018 at 6:02 am

    Hello,

    I’m attempting to trigger a 2-second opacity increase from (100 to 0) on a layer as soon as it’s y position exceeds 1000.

    This only needs to occur once on each layer it is applied to. After much thought, experimentation and reading I’m stumped but believe it’s achievable.

    Below is the expression I’m using on the layers opacity property. Any help or wisdom is greatly appreciated.

    Thank you.

    yPos = transform.position[1];
    start = inPoint+time;
    end = inPoint+(time+fadeDur);
    fadeDur = 2;
    lin = linear(time,start,end,100,0);

    if (yPos > 1000) {
    lin
    } else {
    100
    }
    ;

    Brian Swarthout replied 7 years, 10 months ago 3 Members · 9 Replies
  • 9 Replies
  • Alex Printz

    June 21, 2018 at 3:24 pm

    I don’t think it’s going to be as simple as you are expecting. Expressions have to be re-run each frame and cannot carry over variables between frames.

    You would need to be doing a recursive search for each frame that happened prior to the current frame to check for when y>1000, and then from that frame linear forward 2 seconds.

  • Brian Swarthout

    June 22, 2018 at 1:13 am

    Hi Alex,

    Thanks for the information. I was afraid this was going to be the case. I’ll try my best at picking apart Dan’s triggering expression to see if I can make it work for my purposes.

    Does the fact that the position of the layer will be driven by the position of a null change anything or will the expression still need to top a recursive search?

    Thanks again,

    – Brian

  • Dan Ebberts

    June 22, 2018 at 6:23 am

    Try this:


    t = inPoint;
    p = transform.position;
    v = 100;
    while (t < time){
    if (p.valueAtTime(t)[1] > 1000){
    v = linear(time - t,0,2,100,0);
    break;
    }
    t += thisComp.frameDuration;
    }
    v

    Dan

  • Alex Printz

    June 22, 2018 at 1:56 pm

    Dan, I like the using inPoint as the beginning of the search, that’s an efficient touch.

  • Brian Swarthout

    June 23, 2018 at 12:13 am

    Hello!

    Dan, This worked. Thank you so much.

    This will prove incredibly useful and I’m excited to pick it apart to understand it’s mechanics.

    One question I have is… Why must the [1] be input after p.valueAtTime(t) rather than just in the “p” variable itself?

    Thanks so much!

  • Dan Ebberts

    June 23, 2018 at 12:18 am

    If you don’t use the [1], you’ll get both the x and y values, which won’t give you the result you want.

    Dan

  • Brian Swarthout

    June 26, 2018 at 5:18 am

    Thanks for the quick response! I’m aware of using [1] to reference the second value in an array but was unsure why it must be specified following the valueAtTime function rather than in the variable itself. See below for the expression that is not working. Is it due to how valueAtTime works?


    t = inPoint;
    p = transform.position[1];
    v = 100;
    while (t &lt; time){
    if (p.valueAtTime(t) > 1000){
    v = linear(time - t,0,2,100,0);
    break;
    }
    t += thisComp.frameDuration;
    }
    v

  • Dan Ebberts

    June 26, 2018 at 5:40 am

    valueAtTime() returns an array, which you are then trying to compare to a scalar (1000). You need to pick one component of the array for the comparison, which is what the [1] does.

    Dan

  • Brian Swarthout

    June 28, 2018 at 4:45 am

    Makes sense. Can’t thank you enough for your help!

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