Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Time Remap frame controller based on the position of a null object

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

    Posted by Alex Covella on November 16, 2014 at 10:36 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

    Alex Richman replied 7 years, 9 months ago 4 Members · 13 Replies
  • 13 Replies
  • Dan Ebberts

    November 16, 2014 at 6:08 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

  • Alex Covella

    November 17, 2014 at 7:03 am

    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);

  • Alex Covella

    November 28, 2014 at 9:12 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.

  • Dan Ebberts

    November 28, 2014 at 3:59 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

  • Alex Covella

    November 29, 2014 at 8:50 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

  • Dan Ebberts

    November 29, 2014 at 5:31 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

  • Alex Covella

    November 29, 2014 at 7:13 pm

    Thank you Dan,
    you made me happy. 🙂

  • Justin Maloney

    March 20, 2015 at 5:35 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);

  • Dan Ebberts

    March 20, 2015 at 5:55 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

  • Justin Maloney

    March 20, 2015 at 6:16 pm

    That worked! =D Yay!

    Thanks again for the solution, and the knowledge!

Page 1 of 2

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