Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move layer from exact position A to B and hold time X

  • Dan Ebberts

    August 15, 2019 at 11:29 pm

    If you define your curved motion with 3 keyframes (A position, B positon, A position), something like this should work:

    seedRandom(index,true);
    holdDur = random(5,20);
    moveDur1 = key(2).time – key(1).time;
    moveDur2 = key(3).time – key(2).time;

    t1 = holdDur;
    t2 = t1+moveDur1;
    t3 = t2+holdDur
    t4 = t3+moveDur2;

    t = time % t4;

    if (t < t1){
    tCur = key(1).time
    }else if (t < t2){
    tCur = linear(t,t1,t2,key(1).time,key(2).time)
    }else if (t < t3){
    tCur = key(2).time
    }else{
    tCur = linear(t,t3,t4,key(2).time,key(3).time)
    }
    valueAtTime(tCur)

    Dan

  • Michael Kampe

    August 19, 2019 at 3:25 pm

    Hi Dan,

    you are the best. Thank you so much… that’s exactly what I need. ????

    I made a mistake ???? in terms of keyframes. I need at least 4 and not 3. 6 would be even better.
    The point is, I need an “in-between” keyframe, that hold the layer in position until it start to go back to position A. Right now (with only 3 keyframes) it moves from position A to B (as expected) and then straight back to point B. I need a “resting” moment for position B.

    I tried to look into your script, but to insert an additional key(4) is above my knowledge.

    Thank you again for your help
    best
    Michael

  • Dan Ebberts

    August 19, 2019 at 5:05 pm

    For 4 keyframes, I think you just need to change this line:

    tCur = linear(t,t3,t4,key(2).time,key(3).time)

    to this:

    tCur = linear(t,t3,t4,key(3).time,key(4).time)

    Dan

  • Rasmus Hansen

    August 20, 2019 at 1:02 pm

    Hi Dan,

    Hope it’s okay I interrupt here. I used your code and managed to tweak it a bit to my liking. Now it looks like this, so I have a box going in and out of the frame repeatedly.

    What I now want to do is to be able to change the size of the rectangles, to a random size, whenever the rectangle hits the posDown position. And then KEEP that same size until the next time it reaches posDown.

    Is that even possible? I played around with using random() on the size property, but it’s changing the size at random at every frame – and if I use seedRandom, it always changes to the same size at every loop. Moreover, I can’t get it to stay at that size.

    Just slowly getting the hang of expressions. Challenging, a bit frustrating, but very rewarding!

    Thanks in advance.

    seedRandom(index,true);
    blobSize = content("Rectangle 1").content("Rectangle Path 1").size[0];
    holdDur = random(3,4);
    moveDur = linear(blobSize,100,500,1,50);
    posUp = -blobSize*0.5;
    posDown = thisComp.height+blobSize*0.5;

    t1 = holdDur;
    t2 = t1+moveDur;
    t3 = t2+holdDur;
    t4 = t3+moveDur;

    t = time % t4;

    if (t &lt; t1){
    posDown
    }else if (t &lt; t2){
    easeOut(t,t1,t2,posDown,posUp)
    }else if (t &lt; t3){
    posUp
    }else{
    ease(t,t3,t4,posUp,posDown)
    }

  • Michael Kampe

    August 20, 2019 at 1:24 pm

    Hi Dan,

    thank you for your help. It worked, but its a little bit odd, that the

    holdDur = random(5,20); always “waits” 5 sec.

    And it doesn’t matter what value I’m using (.1,10) or (10,100)… still 5 sec. until it start again.
    My keyframes are Position A —1sec—Position B—1sec—Position B —1sec—Position A.

    Really strange.

    Any idea? Thank you very much again for your help.
    Best
    Michael

  • Michael Kampe

    August 20, 2019 at 4:55 pm

    Hi Rasmus,

    I don‘t know how Dan sees it, but would it be better if you open a new thread to ask your problem there? I mean, this thread is about position and hold time and not about scaling etc. even if you use part of the same script.

    I think it‘ll help
    a) Dan to not get too confused and
    b) help the others better in the forum if they have a similar problem

    Don‘t you think?

    Just sayin‘
    Michael

  • Rasmus Hansen

    August 20, 2019 at 7:53 pm

    Hi Michael,

    You are so right. Didn’t mean to cause confusion or hi-jack the thread. My bad!

    The new thread (about changing size / position at random) can be found here:
    https : // forums . creativecow . net / thread / 227/42615

Page 2 of 2

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