Activity › Forums › Adobe After Effects Expressions › Store the time at which a variable reaches a value
-
Store the time at which a variable reaches a value
Posted by Xavier Gomez on October 13, 2011 at 12:04 pmHello,
I would like to store the time of the comp at which a certain quantity reaches a given value for the first time.
I bet it is pretty elementary but, well, i’m still a beginner (I did search the Adobe After Effects Expressions forum).
Dan Ebberts replied 14 years, 10 months ago 2 Members · 5 Replies -
5 Replies
-
Dan Ebberts
October 13, 2011 at 2:33 pmExprssions can’t “store” anything. All they can do is set the value of the property hosting the expression. To do what you want to do, your expression will have to look at the property’s value starting at time = 0, frame by frame, until it finds the first frame where the value reaches your target value.
Dan
-
Xavier Gomez
October 13, 2011 at 4:29 pmOk, i’ll put it differently.
The main layer’s position is given by transform.position + Delta-pos(the exact form of the expression Delta-pos is irrelevant here). But,
(1) i want it to be zero until something happens in some other layer
(a quantity, say k, reaches a threshhold value, say k_threshhold);
(2) after that i only know the expression of Delta-pos in local time (time-T) for time>T, where T is the time at which the threshhold was reached. But,… i dont know T ! and i dont know how to tell AE what is the value of T. -
Dan Ebberts
October 13, 2011 at 4:40 pmLike I said, you’ll need to do a frame-by-frame search for the threshold crossing. It will be something like this (not tested):
k_threshold = 10;
P = (whatever property you're monitoring);
trig = false;
for (f = 0; f <= timeToFrames(); f++){
T = framesToTime(f);
if (P.valueAtTime(T) > k_threshold){
trig = true;
break;
}
if (trig){
(do something with T)
}else{
0
}
Dan
-
Xavier Gomez
October 13, 2011 at 5:47 pmThank you, working !
I am still wondering about optimization: this time T either doesnt exist (the threshold is never reached), either is unique (since it is the FIRST time the threshold is reached). So ideally it should be computed only once for the whole composition, and not at each frame.
-
Dan Ebberts
October 13, 2011 at 6:22 pmExpressions can’t store any data for use at later frames. So at each frame, it has to again search for a threshold crossing.
Dan
Reply to this Discussion! Login or Sign Up