top of page
Distance Based Offset Expression
Time Based Animation, Dynamic, Advanced Expression
Distance Based Offset Expression
The Distance-Based Y Offset Expression adjusts a layer's Y position based on its 3D distance from a target, using sliders to control the range and maximum offset for a dynamic, reactive effect.
The Distance-Based Y Offset Expression adjusts a layer's Y position based on its 3D distance from a target layer. By using two sliders on a Controller Layer (for Max Y and Range), the Y offset increases as the Target Layer moves further away. The `ease()` function smooths the transition, creating a dynamic effect where the Offset Layer reacts to the Target's position.
// References to layers
target = thisComp.layer("Target");
controller = thisComp.layer("Controller");
// Slider values from Controller
maxY = controller.effect("Max Y")("Slider"); // Maximum Y offset
range = Math.max(controller.effect("Range")("Slider"), 1); // Prevent zero or negative range
// Calculate 3D distance between Target and Reactive Layer
dist = length(target.position, position);
// Map distance to a Y offset using ease
yOffset = ease(dist, 0, range, maxY, 0);
// Return the adjusted position (modify only Y)
[position[0], position[1] + yOffset, position[2]];
How to Use This Expression?
Explanation:
Target Layer: The layer that moves around (this could be a camera, null, or object).
Controller Layer: Contains the sliders (
Max Y
andRange
) that control the intensity of the Y offset.As the Target Layer moves further away, the Offset Layer will adjust its Y position accordingly.
How It Works:
The Range slider controls the distance at which the effect starts and ends.
The Max Y slider controls the maximum Y offset based on the distance to the Target Layer.
Trending
bottom of page