Skip to main content
mistikde
Participating Frequently
January 23, 2017
Question

trigger fade animation if condition is true

  • January 23, 2017
  • 1 reply
  • 1254 views

hey guys im trying to achieve something like this roughly where as soon as the condition is true it triggers a fade animation but i have no clue how to do it. this just cuts to a value of 100.

a = thisComp.layer("Null").transform.position[0]

if (a>10)

linear(time, 0,100)

else

0

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
January 23, 2017

It's tricky. Since expressions have no memory, your expression has to start at the current frame and go back in time, frame by frame, using valueAtTime(), until it finds the frame where the value went from below 10 to above 10. Something like this:

P = thisComp.layer('Null')('Transform')('Position');

fadeTime = 1;

threshold = 10;

trig = false;

for (f = timeToFrames(time); f >= 0; f--){

  tCur = framesToTime(f);

  v = P.valueAtTime(tCur)[0];

  if (trig && (v < threshold)) break;

  if (v >= threshold) trig = true;

}

t = trig ? time - framesToTime(f+1) : 0;

ease(t,0,fadeTime,value,0)

Dan

mistikde
mistikdeAuthor
Participating Frequently
January 28, 2017

thanks Dan it is animating, but its animating from 100 to 0 in the first second no matter what. it doesn't seem to take the trigger into account at all.

i modified it a little but basically this is closer to what im trying to do. when the null moves over the layer fade in. right now with your help i got it to switch but its not animating with a duration. is it the if (trig) statement?

w = this.sourceRectAtTime().width;

h = this.sourceRectAtTime().height;

fadeTime = 1

Parent = thisComp.layer("Null 1").transform.position;

Child = transform.position;

min = 50

max = 100

threshold = 0

var trig = true;

for (f = timeToFrames(time); f >= 0; f--){

  tCur = framesToTime(f);

hdis = length(Parent[0],Child[0]);

vdis = length(Parent[1],Child[1]);

if ((hdis <= w/2+threshold) && (vdis <= h/2+threshold)) trig = false;

if ((hdis > w/2+threshold) && (vdis > h/2+threshold)) trig = true; 

}

if(trig){

t = time - framesToTime(f+1)

ease(t,0,fadeTime,min,max)

}

else{

t = time - framesToTime(f+1)

ease(t,0,fadeTime,max,min)

}