Control End Animation Position with Slider

This After Effects expression is designed to control a property’s value using a slider based on the time between two keyframes. Here’s how it works step by step:

if (numKeys > 1) {
   key1Time = key(1).time; // Time of the first keyframe
   key2Time = key(2).time; // Time of the second keyframe
   key1Val = 0; // Value at the first keyframe (start)
   key2Val = thisComp.layer("Expression Controls").effect("Slider Control")("Slider"); // Value controlled by the slider
   sliderVal = ease(time, key1Time, key2Time, key1Val, key2Val); // Interpolation using ease function based on time between keyframes
} else {
   value; // Return the current value if there's only one keyframe
}
  1. Controller Setup:
    • First, you create a new empty shape layer named “Expression Controls”. This layer will serve as the controller layer for any expressions in your composition.
    • On this layer, you add a “Slider Control” effect. This slider control will be used to control the property value on another layer.
  2. Path Creation:
    • Create a second shape layer and draw a path using the pen tool.
    • Go to Window > Create Nulls from Paths, and select “Trace Path”. This action converts the path into keyframes on a null object.
    • Ensure the “loop” option is turned off for the path animation.
    • Add a start point keyframe at 0% and an end-point keyframe one second later at 100%. This animates the path from start to finish over one second.
  3. Expression on Progress:
    • Apply the expression from above to the progress property of the path animation

Explanation of Expression:

  • The expression first checks if there are more than one keyframes (numKeys > 1). If not, it returns the current value (value).
  • If there are two keyframes, it retrieves the time and value of each keyframe.
  • The slider control on the “Expression Controls” layer determines the value at the second keyframe.
  • Using the ease() function, the expression interpolates between the values based on the time between the two keyframes. This ensures smooth animation between the two values as the path progresses.
  • The interpolated value is then assigned to the sliderVal variable and returned.
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *