Activity › Forums › Adobe After Effects Expressions › Stop loop expression at certain time period
-
Stop loop expression at certain time period
Posted by Krishna Moorthy on May 3, 2017 at 12:21 pmI have created a looping animation using the expression,
as I want only the last two keyframes to loop. Now, the solution am looking for is to stop the loop at some point of time of my choice. Am sure that, it can be done by tweaking the above expression a little. Kindly, anyone help me with the issue. Will provide additional information, if above details are not clear.
Thank in advance.
loopOut(type = "pingpong", numKeyframes = 1)Andy Engelkemier replied 6 years, 1 month ago 6 Members · 7 Replies -
7 Replies
-
Kevin Camp
May 3, 2017 at 9:05 pmI think you’ll need to roll-your-own loop expression.
try this:
dur = 5; // value in seconds
if ( numKeys > 0 ) {
loopDur = key(numKeys).time - key(1).time;
if ( time < dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur );
}Kevin Camp
Art Director
KCPQ, KZJO & KRCW -
Krishna Moorthy
May 5, 2017 at 6:21 amHi,, Thanks for your reply mate.
AE throws an error when I used your expression, the error is, “expected )”
Could you please explain the expression, so that I can figure out what is the issue with it.
Thank you!
-
Kevin Camp
May 5, 2017 at 2:12 pmthe less-than sign was replaced by ‘<‘ when posting…
I also should have added the ‘else’ in case there were no keyframes…. i’ll try the expression with a performated tag:
dur = 5; // value in seconds if ( numKeys > 0 ) { loopDur = key(numKeys).time - key(1).time; if ( time < dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur ); } else { value; }essentially the expression is using the valueAtTime() function to build a loop. by using the modulus (that’s the % sign function) of the current time for a given period (in this case loopDur, that is derived by the times of the first an last keyframes), you can create your own looping expression.
using the if statement, it will loop until the time specified by the ‘dur’ variable.
valueAtTime( due % loopDur ) just sets the value (or point in the loop) to hold at that time specified by ‘dur’.
Kevin Camp
Art Director
KCPQ, KZJO & KRCW -
Suhair Vennakkad
December 27, 2017 at 8:29 amthank you Kevin Camp_it’s very usefull
dur = 15; // value in secondsif ( numKeys > 0 ) {
loopDur = key(numKeys).time - key(1).time;
if ( time < dur ) valueAtTime( time % loopDur ) else valueAtTime( dur % loopDur );
} else {
value;
}
-
Colby Turybury
June 16, 2018 at 8:55 pmHow about the looping be based on number of loops instead of time. Say 10 loops. How would you go about that?
-
Dan Ebberts
June 17, 2018 at 1:02 pmThat would be something like this:
nLoops = 10;
if (numKeys > 1){
loopDur = key(numKeys).time - key(1).time;
n = Math.floor((time - key(1).time)/loopDur);
if (n < nLoops){
t = (time - key(1).time)%loopDur;
valueAtTime(key(1).time + t);
}else{
valueAtTime(key(numKeys).time);
}
}else
value;
Dan
-
Andy Engelkemier
March 20, 2020 at 1:20 pmso I’m not great at math, which makes me not great at writing expressions. I get lost at the valueAtTime part. You know, the part that says what actually happens.
I’m not sure about the %. I don’t really understand how to practically apply what modulo is.
That being said. It works, but i need it to stop looping at the End of the loop. My loop is intentionally abrupt, so the beginning and end are opposite. I want to just say else value at key(2) (there are 3 keys) but not sure if that’s possible.
Reply to this Discussion! Login or Sign Up