View all expressions
Interpolation

Inherit Rotation from Nearest Layer

Finds the closest layer in the comp and copies its rotation in real time. The closest object controls how this layer rotates.

Contributed by:


minDist = 1e6;
closestRot = 0;
for (i = 1; i <= thisComp.numLayers; i++)
{
if (i != index)
{
d = length(position, thisComp.layer(i).position);
if (d < minDist)
{
minDist = d;
closestRot = thisComp.layer(i).rotation;
}}}
closestRot;

Inherit Rotation from Nearest Layer

Practical use case

Useful for swarm, flock, or system animations where objects orient toward nearby elements - also great for connecting elements or auto-aligned labels.

Check out similar expressions

Data-driven video workflows for After Effects are easier with Plainly.

a mesh of elegant lines transparent image