ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trigger linear Interpolation

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Brian Swarthout
Trigger linear Interpolation
on Jun 21, 2018 at 6:02:09 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
}
;




Return to posts index

Alex Printz
Re: Trigger linear Interpolation
on Jun 21, 2018 at 3:24:37 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.


Return to posts index

Brian Swarthout
Re: Trigger linear Interpolation
on Jun 22, 2018 at 1:13:47 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


Return to posts index


Dan Ebberts
Re: Trigger linear Interpolation
on Jun 22, 2018 at 6:23:26 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



Return to posts index

Alex Printz
Re: Trigger linear Interpolation
on Jun 22, 2018 at 1:56:34 pm

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


Return to posts index

Brian Swarthout
Re: Trigger linear Interpolation
on Jun 23, 2018 at 12:13:21 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!


Return to posts index


Dan Ebberts
Re: Trigger linear Interpolation
on Jun 23, 2018 at 12:18:27 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



Return to posts index

Brian Swarthout
Re: Trigger linear Interpolation
on Jun 26, 2018 at 5:18:21 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


Return to posts index

Dan Ebberts
Re: Trigger linear Interpolation
on Jun 26, 2018 at 5:40:58 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



Return to posts index


Brian Swarthout
Re: Trigger linear Interpolation
on Jun 28, 2018 at 4:45:06 am

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


Return to posts index

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