Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Linking rotation in one comp to position of layer at main comp using valueAtTime

  • Linking rotation in one comp to position of layer at main comp using valueAtTime

    Posted by Diogo Mendes-pinto on May 27, 2020 at 10:18 am

    Hi!

    I’m trying to make a layer rotate using the position value of another layer on the main comp to make something like a follow through motion as seen here https://www.toolfarm.com/tutorial/after_effects_simulate_cloth_animation_expression/

    I’m using Position instead of Anchor Point so the expression I used is

    p = comp("Slide3").layer("SW_Robot_1").transform.position;
    d = p.valueAtTime(time) - p.valueAtTime(time - .1);

    (d[0] + d[1]);

    The problem is that although I’m using the “time” to tell AE to use the current cursor time it retrieves the same value wherever the cursor is.

    PS: When I use a specific time instead of “time” the value retrieved seems to be ok.

    EDIT: I realised that actually the expression is working as it should it just happens 15s in the future as this is the offset of the two layers starting point.
    I’m trying to offset the expression but haven’t found a solution yet.

    Can someone help please?
    Thanks

    Diogo Mendes-pinto replied 6 years, 3 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    May 27, 2020 at 2:51 pm

    If I understand how you have this set up, you need to adjust the time by the offset of the precomp’s start time within the main comp, like this (not tested):

    C = comp(“Slide3”);
    L = C.layer(thisComp.name);
    p = C.layer(“SW_Robot_1”).transform.position;
    d = p.valueAtTime(time + L.startTime) – p.valueAtTime(time + L.startTime – .1);

    (d[0] + d[1]);

    Dan

  • Diogo Mendes-pinto

    May 28, 2020 at 12:13 am

    Dan,

    Thank you for your response. It worked great. I just had to make a little change to make it work as I needed.

    C = comp("Slide3");
    L = C.layer(thisComp.name);
    p = C.layer("SW_Robot_1").transform.position;
    d = p.valueAtTime(time + L.startTime) - p.valueAtTime(time + L.startTime + .1);

    (d[0] + d[1]);

    Now I have another question: how do I keep the result to be no less than -20? I mean, how do I keep the value inside an interval? Something like (-20,20).

    Thank you!

  • Dan Ebberts

    May 28, 2020 at 12:23 am

    Try replacing the last line with:

    clamp(d[0] + d[1],-20,20);

    Dan

  • Diogo Mendes-pinto

    May 28, 2020 at 9:09 am

    It’s all working as intended now.

    Thank you very much Dan!

    Cheers!

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