ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Diogo Mendes-Pinto
Linking rotation in one comp to position of layer at main comp using valueAtTime
on May 27, 2020 at 10:18:51 am
Last Edited By Diogo Mendes-Pinto on May 27, 2020 at 2:12:05 pm

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_ex...

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


Return to posts index

Dan Ebberts
Re: Linking rotation in one comp to position of layer at main comp using valueAtTime
on May 27, 2020 at 2:51:22 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



Return to posts index

Diogo Mendes-Pinto
Re: Linking rotation in one comp to position of layer at main comp using valueAtTime
on May 28, 2020 at 12:13:53 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!


Return to posts index


Dan Ebberts
Re: Linking rotation in one comp to position of layer at main comp using valueAtTime
on May 28, 2020 at 12:23:33 am

Try replacing the last line with:

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


Dan



Return to posts index

Diogo Mendes-Pinto
Re: Linking rotation in one comp to position of layer at main comp using valueAtTime
on May 28, 2020 at 9:09:10 am

It's all working as intended now.

Thank you very much Dan!

Cheers!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]