Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Controlling z axis in layer to bring image to front of the rest

  • Controlling z axis in layer to bring image to front of the rest

    Posted by Mark Mitchell on February 26, 2019 at 4:23 pm

    I have 8 layers and I currently have them scaling up as they are passed across like Apple Doc. The issue is as they scale because of the layer order parts of the graphics are hidden beneath the layer objects on either side. So, I need to be able to bring the layers Z axis forward each time it is passed across. I have tried Dan Ebberts script attached but this only works with 1 layer, I am guessing I am missing a parameter in the script to adjust for each layer it’s applied to? Any Help would be great – Dan, if you see this please respond. I’ve attached an example image demonstrating the problem.

    below = 0;
    for (i = 1; i <= thisComp.numLayers; i++){
    if (i == index) continue;
    if (thisComp.layer(i).position[1] < value[1]) below--;
    }
    [value[0],value[1],below]

    Regards

    Mark

    Dan Ebberts replied 7 years, 2 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 26, 2019 at 6:46 pm

    What does your scale expression look like?

    Dan

  • Mark Mitchell

    February 26, 2019 at 6:49 pm

    Hi Dan,
    Here is the expression –

    // Scale with control layer
    // Applied to scale parameter

    // Point1 is current layer, point2 is control layer
    point1=thisLayer.position;
    point2=thisComp.layer("Drag Me").position;

    // Find the vector between the 2 points
    delta=sub(point1, point2);

    // Now find the length
    distance=length(delta);

    //Remap distance to large scale when near, small when far
    linear(distance, 0, 100, [250,250], [75,75]);

    Regards

    Mark

  • Dan Ebberts

    February 26, 2019 at 7:06 pm

    Something like this should work:


    L = thisComp.layer("Drag Me");
    point2= L.position;
    myMin = 999999;
    minIdx = 0;

    for (var i = 1; i <= thisComp.numLayers; i++){
    if (i == L.index) continue;
    point1=thisComp.layer(i).position;
    delta=sub(point1, point2);
    distance=length(delta);
    if (distance < myMin){
    myMin = distance;
    minIdx = i;
    }
    }
    z = (minIdx == index) ? 1 : 0;
    [value[0],value[1],z]

    Dan

  • Mark Mitchell

    February 26, 2019 at 7:28 pm

    Hi Dan,
    Kind of works, apart it sends the focus page to the back. Looks like there it just needs reversing to go to the front.

    Regards

    Mark

  • Dan Ebberts

    February 26, 2019 at 7:43 pm

    Yeah, sorry. Change this line:

    z = (minIdx == index) ? 1 : 0;

    to this:

    z = (minIdx == index) ? -1 : 0;

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy