Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move, hold, move based on layer duration

  • Move, hold, move based on layer duration

    Posted by Adam Haas on January 8, 2018 at 11:57 pm

    I have a script that fades in and fades out based on my layer’s duration (huge time saver).

    Now I’m wondering if I can have my layer (text) start at one position, move to a second position, hold on that position, and then move to a third position.

    Ideally, each change in position would occur over a quarter of a second, and the hold would be anything in between.

    I have a huge animation with text and AI layers and I’m trying to bring consistency without having to deal with the insane amount of keyframes I already have.

    Matthew Talesfore replied 7 years, 3 months ago 4 Members · 11 Replies
  • 11 Replies
  • Scott Mcgee

    January 9, 2018 at 9:16 am

    There is probably better ways to do this.

    a is when you want the animation to happen, I’ve included inPoint of the layer, so that if you move the layer, it’ll re adjust itself.
    t is the time the animation will last.
    posa is the first position
    posb is the second position it will hold on
    posc is the final position

    a = 4;
    t =.5;

    posa = [0,0];
    posb = [100,100];
    posc = [100,1000];

    if((time > inPoint) && (time < inPoint + a)){
    ease(time,inPoint,inPoint+t,posa,posb)
    }else{
    ease(time,inPoint + a,inPoint + a + t,posb,posc)
    }

    Like I said, there is probably an easier method, but this is how I would do it currently at my level of expertise.

    Hope this is of use

  • Adam Haas

    January 9, 2018 at 6:19 pm

    You definitely pushed me in the right direction. I was able to simplify it a bit. I didn’t need the “a” variable, because I want to base it on the length of the layer. I also noticed that the first frame of the layer was being caught by the “else” portion of the script, so I changed it to be at or less than the inPoint + the duration of the animation.

    Then as I wanted the else statement to occur at whatever the end of the layer was, I used the outPoint variable minus the animation time.

    Works great, thank you so much!

    t =.25;

    posa = [0,0];
    posb = [100,100];
    posc = [100,200];

    if(time &lt;= inPoint + t) {
    ease(time,inPoint,inPoint + t,posa,posb)
    }else{
    ease(time,outPoint - t,outPoint,posb,posc)
    }

  • Scott Mcgee

    January 10, 2018 at 8:21 am

    You can tell I don’t read posts thoroughly.

    If you got that to work brill.

    An alternative, as well is (time < (inPoint + outPoint)/2) which simply means, if I’m before the middle of the layer. I use this a lot, for scaling and position, but I’ve never had to go to a third point.

    t =.25;

    posa = [0,0];
    posb = [100,100];
    posc = [100,200];

    if(time < (inPoint + outPoint)/2) {
    ease(time,inPoint,inPoint + t,posa,posb)
    }else{
    ease(time,outPoint – t,outPoint,posb,posc)
    }

    it makes no difference really i think… With me still getting used to expressions 2 years later < or >…they break my brain haha, as I don’t know if they have a significant difference to writing it < or >.

    Anyways…Glad it’s working.

  • Matthew Talesfore

    January 16, 2019 at 8:51 pm

    Hi Scott,
    This piece of code you wrote is awesome and so close to what I am trying to achieve.
    I can Franken-code expressions, but my current problem is way over my head…

    Currently, I am trying to move one layer to a series of pre-defined positions, pausing in between each one.
    Much like your script currently does, the movements can all use the same pause length and the same transition time.
    However, for my purposes, I need to move a layer from it’s starting position to 6 different relative positions, instead of the 3 absolute positions. Additionally, I want the first movement to start after the time interval has passed, not at the layer inPoint. The movements should not repeat.

    Any help you can offer would be appreciated, I have been going in circles on this for the last couple days.

    Thanks!

    Matt T

    http://www.MatthewTalesfore.com

  • Dan Ebberts

    January 16, 2019 at 10:35 pm

    Something like this maybe:


    moveDur = .25;
    holdDur = 1;

    relativePos = [[100,100],[200,200],[300,300],[400,400],[500,500],[600,600]];

    seg = Math.floor((time - inPoint)/(holdDur+moveDur));

    if (seg >= relativePos.length){
    p = relativePos[relativePos.length-1];
    }else{
    phase = (time - inPoint)%(holdDur+moveDur);
    if (phase < holdDur){
    p = (seg == 0) ? [0,0] : relativePos[seg-1];
    }else{
    pCur = (seg == 0) ? [0,0] : relativePos[seg-1];
    pNext = relativePos[seg];
    p = linear(phase,holdDur,holdDur+moveDur,pCur,pNext);
    }
    }
    value + p

    Dan

  • Matthew Talesfore

    January 16, 2019 at 10:50 pm

    I feel very honored that you responded to my post!
    Your code works beautifully and simply.
    I know it took me longer to write my question than it took you to write the code.
    A coffee coming your way Dan!

    THANKS!

    Matt T

    http://www.MatthewTalesfore.com

  • Adam Haas

    January 17, 2019 at 5:07 pm

    Maybe you can help me with this part. I have the same thing but now it’s only two positions.

    // Shift position, hold

    t =.5;
    EndPos = position;
    StartPos = [EndPos[0],EndPos[1]+30];

    if(time <= inPoint + t) {
    ease(time,inPoint,inPoint + t,EndPos,StartPos)
    }

    This worked at the time of my last post, but since AfterEffects was updated for 2019, the code has stopped working and now says:

    After Effects warning: Expression Disabled
    Error at line 1 in property 'Position' of layer 1
    ('Shape Layer 1') in comp 'Expression Testing'

    expression result must be a dimension of 2, not 1.

  • Dan Ebberts

    January 17, 2019 at 5:45 pm

    That expression isn’t structured quite right. It doesn’t provide a result when (time > inPoint + t). The simplest fix is to do something like this:

    t =.5;
    EndPos = position;
    StartPos = [EndPos[0],EndPos[1]+30];

    ease(time,inPoint,inPoint + t,EndPos,StartPos)

    Dan

  • Adam Haas

    January 17, 2019 at 6:03 pm

    Just watched your demo reel. Wow, your work is super impressive. I hope to achieve your level of quality one day.

  • Adam Haas

    January 17, 2019 at 6:04 pm

    That did the trick. Thank you so much Dan.

Page 1 of 2

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