Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Converting one layer’s rotation to another’s Y value

  • Converting one layer’s rotation to another’s Y value

    Posted by Navarro Parker on October 5, 2012 at 5:47 pm

    I’m trying to use a range mapper to convert Layer A’s Z Rotation (0-45°) to Layer B’s Y Position (+/- 100 pixels). Both are 3D layers.

    I think I have the basic concept correct? But I’m getting a class number error in last line of this:

    input = thisComp.layer("Layer A").transform.zRotation;
    inputLow = 0;
    inputHigh = 45;
    outputLow = -100;
    outputHigh = 100;
    m = linear(input,inputLow,inputHigh,outputLow,outputHigh);
    [value[0], value + m[1], value[2]]

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

    October 5, 2012 at 6:07 pm

    I haven’t tried it, but I think you just need to change the last line to this:

    [value[0], value + m, value[2]]

    or this,

    value + [0,m,0]

    Dan

  • Navarro Parker

    October 5, 2012 at 6:10 pm

    Your solution works great (of course)!

    Generally speaking, when should I be use (and not use) [0], [1], [2]? I thought 3D position was an array.

    Also, should I be using degreesToRadians?

    In the meantime, I came up with this. But it feels clunky:

    x = thisComp.layer("green").transform.position[0];
    y = thisComp.layer("green").transform.position[1];
    z = thisComp.layer("green").transform.position[2];

    input = thisComp.layer("solid").transform.rotation;
    inputLow = -45;
    inputHigh = 45;
    outputLow = -100;
    outputHigh = 100;
    m = linear(input,inputLow,inputHigh,outputLow,outputHigh);
    [x, y+m, z]

  • Dan Ebberts

    October 5, 2012 at 6:28 pm

    I may have added to your confusion. I got the first option wrong. It should have been:

    [value[0], value[1] + m, value[2]]

    > I thought 3D position was an array.

    It is. But your variable m isn’t, so it doesn’t need array indexing. I like the second option (value + [0,m,0]) where you just let AE do the vector (array) math for you.

    >Also, should I be using degreesToRadians?

    Generally not unless you use one of the JavaScript trig functions.

    Dan

  • Navarro Parker

    October 5, 2012 at 6:49 pm

    [value[0], value[1] + m, value[2]]

    value + [0,m,0]

    They both work fine. Is there a reason I should use one over the other?

  • Dan Ebberts

    October 5, 2012 at 7:17 pm

    Functionally they’re the same. I like the second one because it’s more efficient (and tidier code, I think). The expression engine knows how to add arrays, so I say take advantage of it. 🙂

    Dan

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