ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Time Remap frame controller based on the position of a null object

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Alex Codich
Time Remap frame controller based on the position of a null object
on Nov 16, 2014 at 10:36:27 am

Hi everybody,
I'm trying to control Timeremap frames position from the x value of a null object.

I have a null object ("PIVOT"), and want to control a Composition based on 3 frames by the "x" value of the NullObject.


For example:
From the center to 200px on left and right, the timeremap of my composition will stay at frame 00:02
From 200px till the end of right "x" position value, the timeremap will go at frame 00:03
From 200px till the end of left "x" position value, the timeremap will go at frame 00:01

Thank you,
Alex


Return to posts index

Dan Ebberts
Re: Time Remap frame controller based on the position of a null object
on Nov 16, 2014 at 6:08:13 pm

Something like this, I think:


x = thisComp.layer("Null 1").transform.position[0];
if (x < thisComp.width/2 - 200)
f = 1
else if (x > thisComp.width/2 + 200)
f = 3
else
f = 2;
framesToTime(f);



Dan



Return to posts index

Alex Codich
Re: Time Remap frame controller based on the position of a null object
on Nov 17, 2014 at 7:03:21 am
Last Edited By Alex Codich on Nov 21, 2014 at 7:36:07 pm

Thanks Dan, it works.

x = thisComp.layer("Null 1").transform.position[0];
if (x < thisComp.width/2 - 200)
f = 2
else if (x > thisComp.width/2 + 200)
f = 0
else
f = 1;
framesToTime(f);


Return to posts index


Alex Codich
Re: Time Remap frame controller based on the position of a null object
on Nov 28, 2014 at 9:12:08 am

I Need help for 2 more options:

Option 1:

I have the same composition controlled by a null object but with “5” frames.

Example:
From the center to 100px on left and right, the timeremap of my composition will stay at frame 00:02
From 101px to 200px of right "x" position value, the timeremap will go at frame 00:03
From 201px till the end of right "x" position value, the timeremap will go at frame 00:04
From 101px to 200px of left "x" position value, the timeremap will go at frame 00:01
From 201px till the end of left "x" position value, the timeremap will go at frame 00:00


Option 2:

I have a composition based on 29 frames.
I want to control the playback based on the movement of the “x” value of the Null object in a limited range, from -100px to +100px.
When the Null object is centered the timeremap of my composition will stay at frame 00:15
When I move the Null object from +1px to +100px the composition will playback from 00:16 to 00:29
When I move the Null object from -1px to -100px the composition will playback from 00:14 to 00:00

I thank you in advance.


Return to posts index

Dan Ebberts
Re: Time Remap frame controller based on the position of a null object
on Nov 28, 2014 at 3:59:57 pm

I think the first one will be like this:


x = thisComp.layer("Null 1").transform.position[0];
d = x - thisComp.width/2;
if (d < -201)
f = 0
else if (d < -100)
f = 1
else if (d < 100)
f = 2
else if (d < 201)
f = 3
else
f = 4;
framesToTime(f);


The second one is trickier, because the expression needs to figure out how long it has been off-center to calculate the correct frame. The best way to do that depends on how you control the null. The easiest would be if the expression can just look at the null's most recent keyframe (assuming hold keyframes).

Dan



Return to posts index

Alex Covella
Re: Time Remap frame controller based on the position of a null object
on Nov 29, 2014 at 8:50:06 am

Thank you Dan,
option 1 works perfectly and it's an easy way to control few frames.
At the end I could write the expression even for a composition of 29frames, but I though it would be better and easier to control the playback.

I use the Null always centered in the composition, and the only reference that I care is the "x" position value.
The Null controls the frame position of the timeremap, and when is centered it should stay in the middle of the composition timeline that I want to control, example:
Null controls timeremap of a composition of 29 frames
Null is centered and the time remap is in the middle of the timeline (ex. frame 15)
If I move the Null from center to right, and I can set the range ( ex. 200px), it will play from 15f to 29f between this range.
And the same should work if I move the Null from the center to left, and should play from 15f to 0f.

Alex


Return to posts index



Dan Ebberts
Re: Time Remap frame controller based on the position of a null object
on Nov 29, 2014 at 5:31:52 pm

Ah. I think you threw me with the reference to playing the time remapped layer, but it sounds like what you really need is just something to map the position of the null to the frame number. Something like this might be close to what you're looking for:

x = thisComp.layer("Null 1").transform.position[0];
d = x - thisComp.width/2;
framesToTime(linear(d,-200,200,0,28))


Dan



Return to posts index

Alex Covella
Re: Time Remap frame controller based on the position of a null object
on Nov 29, 2014 at 7:13:21 pm

Thank you Dan,
you made me happy. :)


Return to posts index

Justin Maloney
Re: Time Remap frame controller based on the position of a null object
on Mar 20, 2015 at 5:35:57 pm

Sorry for the bump. I read this thread and the expression worked for me =D

However, when I tried to add more frames I ran into a problem.

I'm trying to switch between 5 frames of a cartoon nose for a character rig I'm working on. Two 90 degree angles (frame 0 and 4), two 45 degree angles (frame 1 and 3), and one center drawing (frame 2).

When I move the layer they're linked to "Eye_Marker" the nose layer cycles through all the frames, except the last one, frame 4.

I've gone over it, and I'm completely stumped. Is there a limit to how many times you can use "else if"?

x = comp("H.M. Character Rig").layer("Eye_Marker (CONTROL)").transform.position[0];

if (x &lt; -200) f = 0;

else if (x &lt; -80) f = 1;

else if (x > 170) f = 3;

else if (x > 250) f = 4;

else f = 2;

framesToTime(f);


Return to posts index


Dan Ebberts
Re: Time Remap frame controller based on the position of a null object
on Mar 20, 2015 at 5:55:34 pm

I think you just need to reverse the order of the tests for 170 and 250, like this:

if (x < -200) f = 0
else if (x < -80) f = 1
else if (x > 250) f = 4
else if (x > 170) f = 3
else f = 2;

because anything that's greater than 250 is also greater than 170 and it will take the first condition that is true.

Dan



Return to posts index

Justin Maloney
Re: Time Remap frame controller based on the position of a null object
on Mar 20, 2015 at 6:16:46 pm

That worked! =D Yay!

Thanks again for the solution, and the knowledge!


Return to posts index

Alex Richman
Re: Time Remap frame controller based on the position of a null object
on Nov 13, 2018 at 7:26:34 am

Hello Dan!!! This code solved my problem! But composition reacting only when i move null object "x" how i can make reacting to y? I change all "x" to "y" in code but it doesn't work:(((

y = thisComp.layer("Null 1").transform.position[0];
d = y - thisComp.width/2;
framesToTime(linear(d,200,-200,0,88))


Return to posts index


Dan Ebberts
Re: Time Remap frame controller based on the position of a null object
on Nov 13, 2018 at 7:48:29 am

I guess it would be like this:

y = thisComp.layer("Null 1").transform.position[1];
d = y - thisComp.height/2;
framesToTime(linear(d,200,-200,0,88))


Dan



Return to posts index

Alex Richman
Re: Time Remap frame controller based on the position of a null object
on Nov 13, 2018 at 8:51:48 am

Thank you very much!!! It worked! :))


Return to posts index

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