Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can you automatically ease transition between 2 values in a Position Array?

  • Can you automatically ease transition between 2 values in a Position Array?

    Posted by Kamil Kurylonek on September 22, 2023 at 9:51 pm

    Hi

    I have an animation, where a number of rows in a table is highlighted by a separate layer with a Blending Mode. To do this manually, it is a bit tedious, as I have to time it with a voiceover – start keyframe, add new keyframe, set another hold keyframe, add new keyframe and so on.

    It is easy, but I have to deal with lot’s of keyframes.

    Ideally, I would like to set a keyframe, when I want the highlight to move to a new position. I would like the expression to ease the transition from previous position to current one.

    My current solution is to do this with a slider and a position array, like this:

    //Define position values
    posOptions = [320, 360, 400, 440, 480];
    
    //Slider to select position from array
    rowSelect = thisLayer("Effects")("rowSelect")("Slider");
    
    //Round down slider values and select relevant item from an array
    newY = posOptions[Math.round(rowSelect)];
    
    //Final position
    [960,newY];

    It works fine, but highlight layer jumps to next position without any ease, due to Math.round function. But without this function, the whole thing does not work.

    Is there a way for expressions to automatically ease between 2 keyframes and hold the value until next keyframe is created? For example, stay on 1st keyframe, until 10 frames before 2nd keyframe – then ease the transition?

    Dan Ebberts replied 2 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Dan Ebberts

    September 22, 2023 at 11:25 pm

    This might get you close. It doesn’t matter what the value of the slider is, the expression just looks at the timing of the keyframes. At the 2nd keyframe, it will ease into the second value of your array, and so on.

    easeTime = framesToTime(10); // ease for 10 frames
    //Define position values
    posOptions = [320, 360, 400, 440, 480];
    //Slider to select position from array
    rowSelect = thisLayer("Effects")("rowSelect")("Slider");
    newY = posOptions[0];
    if (rowSelect.numKeys > 0){
    n = rowSelect.nearestKey(time).index;
    if (time < rowSelect.key(n).time) n--;
    n = Math.min(n,posOptions.length);
    if (n == posOptions.length){
    newY = posOptions[n-1];
    }else if (n > 0){
    y1 = posOptions[n-1];
    y2 = posOptions[n];
    t2 = rowSelect.key(n+1).time;
    t1 = t2 - easeTime;
    newY = ease(time,t1,t2,y1,y2);
    }
    }
    //Final position
    [960,newY];

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