Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change time between keyframes

  • Change time between keyframes

    Posted by Kevin Snyder on May 22, 2017 at 7:04 pm

    Is it possible to change the time between keyframes using expressions? For example, I want to set two keyframes to animate a square’s position over 1 second. Then, I would like to apply an expression that would allow me to play the keyframed animation over a specified amount of time, 3 seconds for example.

    Christian Geijer replied 7 years, 6 months ago 3 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    May 22, 2017 at 7:22 pm

    You can simulate moving a keyframe using valueAtTime(). How would you specify the new timing?

    Dan

  • Kevin Snyder

    May 22, 2017 at 7:58 pm

    That’s a great question…Ideally, I would specify how long the keyframes should play in seconds using a slider…would that be possible?

  • Dan Ebberts

    May 22, 2017 at 8:09 pm

    Something like this maybe:


    dur = effect("Slider Control")("Slider");
    if (time < key(1).time){
    value;
    }else if (time < (key(1).time + dur)){
    t = time - key(1).time;
    d = key(2).time - key(1).time;
    valueAtTime(key(1).time + d*t/dur);
    }else{
    t = time - (key(1).time + dur);
    valueAtTime(key(2).time + t);
    }

    Dan

  • Kevin Snyder

    May 22, 2017 at 9:31 pm

    That works great for two keyframes. Thank you. Is there a flexible way to make it work for multiple keyframes where the number of keyframes can change? Many thanks.

  • Christian Geijer

    October 4, 2018 at 12:22 pm

    Hi,

    A large and late bump, but I thought to reply here instead of starting a new thread.

    I have a template where I’ve placed two sliders with two keyframes each on a control null.
    These two sliders are the “masters” for different animations within the comp. One for “build in” and one for “build out”:

    I’ve written an expression that I can apply to every layer and property I want to control with a linear-function mapped to the “masters”.

    It looks like this:

    animIn = thisComp.layer("Control").effect("Anim in")("Slider");
    animOut = thisComp.layer("Control").effect("Anim out")("Slider");
    dur = thisComp.layer("Control").effect("Duration")("Slider");

    inBuffer = 0;
    outBuffer = 0;

    animInTime = animIn.key(2).time - animIn.key(1).time;
    animOutTime = animOut.key(2).time - animOut.key(1).time;

    animInStart = 0 + inBuffer;
    animOutStart = dur - animOutTime - outBuffer;

    // calculations for inVal, holdVal, outVal, if needed

    holdVal = 100;
    inVal = 0;
    outVal = inVal;

    if(time <= animInStart) {
    inVal
    } else if(time >= animInStart && time < animInStart + animInTime) {
    linear(animIn.valueAtTime(time - animInStart), 0, 100, inVal, holdVal)
    } else if(time >= animOutStart) {
    linear(animOut.valueAtTime(time - animOutStart), 0, 100, outVal, holdVal)
    } else {
    holdVal
    }

    animIn and animOut are the master sliders that go from 0-100 and 100-0 respectively.

    The expression uses the animIn-slider to shift from inVal to holdVal and then holds holdVal.
    It holds holdVal until it’s time to shift, with the animOut-slider, from holdVal to outVal.

    I’ve also built in inBuffer and outBuffer so I can stagger the animation if I want to.

    I’ve tried to integrate your expression in this thread with mine, but I really can’t get it to work. Both due to that I’m not an expert on expressions and that I really don’t understand how yours works.

    In short; I would like to be able to change the duration between the keyframes within animIn and animOut individually with sliders. Is it possible to marry these two expressions together? If yes, how would I go about doing that? Any tips or help you can give me would be appreciated.

    Best regards,
    /C

  • Kevin Snyder

    October 4, 2018 at 3:51 pm

    I would check out this tutorial. I think it will let you get the job done.

    https://www.youtube.com/watch?v=i4rilThiRDE

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Christian Geijer

    October 5, 2018 at 7:11 am

    Awesome. Thanks for the tip!

  • Christian Geijer

    October 19, 2018 at 7:22 am

    I just wanted to return to this in case any stray googler finds this and wonders the same thing.
    I think I’ve solved it. I’m going to expand on this and build some more control over the timings, but the foundation that I’ve built is this. If anyone have some tips for improvement, I appreciate any pointers. But as for now, I think it works.

    Cheers!

    iAnimInKeys = thisComp.layer("Control").effect("Anim in")("Slider");
    iAnimOutKeys = thisComp.layer("Control").effect("Anim out")("Slider");

    tAnimInStart = 1;
    tAnimInDuration = 0.5;

    tAnimOutDuration = 0.5;
    tAnimOutStart = 3;

    holdVal = 880;
    inVal = 200;
    outVal = 540;

    if (time &lt; tAnimInStart){
    inVal

    } else if (time >= tAnimInStart && time &lt; (tAnimInStart + tAnimInDuration)) {
    t = time - tAnimInStart;
    d = iAnimInKeys.key(2).time - iAnimInKeys.key(1).time;
    linear(iAnimInKeys.valueAtTime(iAnimInKeys.key(1).time + d*t/tAnimInDuration), 0, 100, inVal, holdVal)

    } else if(time >= (tAnimInStart + tAnimInDuration) && time &lt; tAnimOutStart) {
    holdVal

    } else if (time >= tAnimOutStart && time &lt; (tAnimOutStart + tAnimOutDuration)) {
    t = time - tAnimOutStart;
    d = iAnimOutKeys.key(2).time - iAnimOutKeys.key(1).time;
    linear(iAnimOutKeys.valueAtTime(iAnimOutKeys.key(1).time + d*t/tAnimOutDuration), 0, 100, outVal, holdVal);

    } else {
    outVal

    }

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