Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move a layer up or down in index when zRotation exceeds or falls below certain value?

  • Move a layer up or down in index when zRotation exceeds or falls below certain value?

    Posted by Casey Labatt-simon on October 20, 2019 at 2:35 pm

    Hi all! I have a mildly complicated question.

    I’m creating an animation with a whole bunch of different cubes, in an isometric perspective, all rotating and moving around. I’m attempting to use Essential Graphics to be able to change how each cube looks from one master composition.

    Because of the isometric perspective, when the cube rotates beyond 180 degrees, the index of the sides of the cube need to be switched so they display in the correct order. Here’s a photo to demonstrate what happens if the layer order is not switched: the right side of the cube shows through the left side at certain degrees.

    I’ve attempted to write an expression to switch the layer order of the “Right Side” and “Left Side” layers using the moveBefore() function whenever the zrotation of the top side of the cube exceeds 180° but I can’t get it to work. One other problem I’m facing is exactly where to put the expression as well. I’ve never dealt with expressions other than ones that directly affect the effect they’re placed on (I.e. looping expression on a rotation) and index isn’t something you can directly place an effect on so I have no idea where to even start here.

    Here’s the preliminary expression I was thinking might work, but does not:


    var rotationval = thisComp.layer(“Top Pattern”).effect(zRotation)

    rotationval > 180 ? thisComp.layer(“rightPattern”).moveBefore() : thisComp.layer(“rightPattern”).moveAfter()

    Would appreciate any help here.

    Dan Ebberts replied 6 years, 9 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    October 20, 2019 at 3:31 pm

    moveBefore() works with scripting, not expressions. Also, expressions can only affect the property hosting the expression, so there’s no way for an expression to affect a layer’s index.

    If you’ve constructed a cube out of 3D layers though, it seems like the “stacking” should take care of itself, unless you’ve done something to break the 3D (like put 2D layers between the 3D layers).

    Dan

  • Casey Labatt-simon

    October 20, 2019 at 10:01 pm

    Ahh I gotcha. For some reason when I rotate it, despite being 3D layers, it definitely doesn’t just take care of itself. It definitely has something to do with the layer order because when I swap the layers around the issue in the photo in my post fixes itself. I guess that’s a post for a separate subforum. Thank you for the reply!!

  • Dan Ebberts

    October 20, 2019 at 10:07 pm

    There are quite a few things that can mess up the interaction of 3D layers. See if any of this applies to your situation:

    https://helpx.adobe.com/after-effects/using/3d-layers.html#3d_layer_interactions_render_order_and_collapsed_transformations

    Dan

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