0

I'm trying to create a new Essential Graphics template in After Effects.

I have an animation (at its most basic, it's a rectangle that expands from a set, small size to - hopefully! - a user defined size) that can be controlled by moving 4 sliders (it took some fiddling about but I've got a Top Left Null and Bottom Right Null and the 4 sliders control their positions (TL X & Y and BR X & Y), which - in turn - determine the positions for the four corners of the rectangle).

However, having begun setting up the template, I'm slightly worried that this is not going to work. Moving the slider control from within the template window just sets new keyframes (so the animation is all over the place) and, thinking about it now, even if using the template in PP doesn't create new keyframes, how will the EG panel know which keyframe (if any) to affect?

I guess what I'm really wondering is if we can, using an expression, cause the slider controls to affect only the LAST keyframe of an animation (I'm no expression whizz but I can't find anything like that out there following some extensive Googling and I cannot figure out a way to write this myself).

Also, if you think there might be an easier way to do any of this, please let me know!

1 Answer 1

1

To use the keyframed value of a property in an expression, there is a value attribute. And properties also have the key() method to access their keys, as well as the numKeys attribute to find out how many keys the property has. Lastly, there's the global time attribute.

So now we've assembled the list of ingredients, here's how you could put it all together. This expression will use the keyframed value up to the last keyframe, and then hand over the reins to the result of an expression, in this case the value of the slider:

// link to your slider, or any calculated value:
var sliderVal = effect("Slider Control")("Slider"); 
var lastKey = key(numKeys);
if (time <= lastKey.time){ // before the last keyframe
  // use the keyframe value before the last keyframe
  value;
} else {  // after the last keyframe
  // control using the sliders, or any expression
  sliderVal;
}

Of course this will jump from the keyframed value to the expression value instantly at the last keyframe. You can interpolate between the values by using one of the interpolation functions. So to interpolate between the keyframed value and the expression value between the second last keyframe and the last keyframe, you might use:

var sliderVal = effect("Slider Control")("Slider"); 
var k2 = key(numKeys); //last key
var k1 = key(numKeys - 1); //second last key    
// linear can take 5 arguments: 
// time, start time, end time, start val, end val
// and interpolates between start val and end val
linear(time, k1.time, k2.time, value, sliderVal)

You could also take advantage of the ease(), easeIn() or easeOut() interpolation functions, which you can just substitue for linear().

1
  • Wow - that's amazing, thank you so much! I'm not in a position to try this out at the moment but, when I do, I'll absolutely let you know how it goes. Thanks again! Commented Apr 16, 2018 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.