top of page

Proximity Expression

Background Line UI

Dynamic, Transform, Time Based Animation, Advanced Expressions

Proximity Expression

This expression scales a layer dynamically based on its proximity to a target, controlled via sliders for maximum scale and range.

This expression scales a layer dynamically based on its proximity to a target. For example, create a null named "Target" and another null named "Controller" with two sliders: Max Scale and Range. Apply the expression to a shape layer’s Scale property, and adjust the sliders to see the shape react to the target’s distance.

// Define the target and controller layers
target = thisComp.layer("Target");
controller = thisComp.layer("Controller");

// Get the maximum scale and range values from the controller
maxScale = controller.effect("Max Scale")("Slider");
range = controller.effect("Range")("Slider");

// Calculate the distance between the target and the current layer
dist = length(target.position, position);

// Smoothly interpolate the scale factor based on the distance
scaleFactor = ease(dist, 0, range, maxScale, 100);

// Return the scale value for both X and Y axes
[scaleFactor, scaleFactor];

How to Use This Expression?

  1. Setup in After Effects: Add two layers and name them "Target" and "Controller".
    Add a slider control effect to the "Controller" layer.

    Rename the sliders to: "Max Scale": Set this slider to define the maximum scaling.
    "Range": Set this slider to define the maximum distance for the effect.

  2. Apply Expression: Select the Scale property of the layer you want to affect.
    Alt + Click (Windows) or Option + Click (Mac) the stopwatch icon for the Scale property.
    Paste the script into the expression editor.

  3. Adjust Parameters: Modify the values of the Max Scale and Range sliders in the Controller layer to see the effect in action.


  • Max Scale = 150: Layers closest to the target will scale up to 150%.

  • Range = 500: The scaling effect will occur within a distance of 500 pixels from the target.

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