Top

After Effects: The Clamp Expression

In After Effects, one useful expression to know is the Clamp expression. This essentially “clamps down” on the values of a layer by creating a minimum and maximum value level.

In the short video tutorial below, we have a background and a circle shape layer. We first separate the X and Y dimensions of the shape layer’s position property. Next, we add two slider controls to the layer and name them X and Y. Then, we set an expression for the X position and pickwhip to the X slider control, and we set an expression for the Y position and pickwhip to the Y slider control. Now, the slider controls move the circle.

But, let’s say you want to keep the circle inside the rectangle. Perhaps you’re making a template and want to confine what users can do. This is where the Clamp expression in After Effects comes into play.

To write the Clamp expression, you need to provide an input, a minimum value, and a maximum value.

clamp(input,min,max)

First, let’s find the minimum and maximum value for our X coordinates. Then, we start the expression by writing “clamp.” Our input is our layer’s slider control, so we can refer to this layer using proper syntax, then add a period before our slider control expression that is already there. This is our input, and now we just need to add the minimum and maximum values. These values are separated by commas.

We do the same for the Y coordinates. First, find the minimum and maximum values, and then write the clamp expression.

Now, no matter what the values are in the slider control, the circle is confined to our given coordinate area.