top of page

Distance Based Offset Expression

Background Line UI

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 and Range) 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.

Support Our Mission to Keep It Free

Your contribution ensures ongoing access to high-quality, easy-to-use After Effects expressions and libraries for

everyone.

Trending
Free After Effects Tutorials & Templates

As one of YouTube's leading creators of Motion Graphic Tutorials, we provide a diverse array of resources, including After Effects templates, royalty-free sound effects, and Photoshop PSD Templates. We also offer premium After Effects Templates and Sound Effects, designed to meet the needs of both beginners and professionals in the Motion Graphics field.

Copyright © 2025 Avnish Parker.

All Rights Reserved.

Follow Us

  • Youtube
  • Grey Facebook Icon
  • Twitter
  • Instagram
  • Patreon_logo_Small_edited_edited
Online Payment Icons
bottom of page