Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Change object size at certain time and make it stick

  • Change object size at certain time and make it stick

    Posted by Rasmus Hansen on August 20, 2019 at 7:48 pm

    Hi there,

    I’m making a lava lamp emulation, and since the end result should be about an hour long, it’s too time consuming to keyframe everything. Therefore, I decided to give expressions a go. Through a lot of studying (thanks, Dan!) and trial and error, I managed to come up with something that works okay.

    What I now want to do is to be able to change the size of the lava blobs, to a random size, whenever the blobs hit the bottom (posDown in the code below). And then KEEP that same size until the next time it reaches posDown. Alternatively, give a random x position when the blobs hit the bottom.

    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.

    Any help is much appreciated.

    Thanks in advance.

    POSITION Y EXPRESSION
    ---------------------------------
    seedRandom(index,true);
    blobSize = content("Ellipse 1").content("Ellipse Path 1").size[0];
    holdDur = random(2,8);
    moveDur = linear(blobSize,100,800,10,40);
    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 < t1){
    posDown
    }else if (t < t2){
    easeOut(t,t1,t2,posDown,posUp)
    }else if (t < t3){
    posUp
    }else{
    ease(t,t3,t4,posUp,posDown)
    }

    POSITION X POSITION
    ------------------------------
    seedRandom(index,true);
    xPosRand = random(thisComp.width);
    xPosWig = wiggle(0.2,200);
    xPos = xPosRand + xPosWig - thisComp.width*0.5;

    [xPos]

    Dan Ebberts replied 7 years, 1 month ago 2 Members · 3 Replies
  • 3 Replies
  • Rasmus Hansen

    August 20, 2019 at 7:48 pm

    What I have now looks like this:

    drive . google . com / open?id=1RCBxJ0UQMhN7kbiFb_7vi_ZfNht1BbXI

  • Rasmus Hansen

    August 31, 2019 at 10:30 am

    Does anyone know if this is somehow possible? 🙂

  • Dan Ebberts

    August 31, 2019 at 8:43 pm

    It’s definitely possible, but somewhat complicated. The issue is that each cycle will have a different duration and since expressions have no memory, the expression will have to reconstruct everything that has occurred in the past. This is a rough attempt at the Y Position expression. It might not be quite right, but it should give you the idea of what you need to do to construct a solution:

    Dan

    blobSize = content("Ellipse 1").content("Ellipse Path 1").size[0];
    moveDur = linear(blobSize,100,800,10,40);
    posUp = -blobSize*0.5;
    posDown = thisComp.height+blobSize*0.5;

    tCur = tPrev = 0;
    cycle = 0;
    while (tCur <= time){
    seedRandom(cycle,true);
    holdDur = random(2,8);

    t1 = holdDur;
    t2 = t1+moveDur;
    t3 = t2+holdDur;
    t4 = t3+moveDur;
    tPrev = tCur
    tCur += t4;
    cycle++;
    }
    if (time >= 0){
    t = time - tPrev;

    if (t < t1){
    posDown
    }else if (t < t2){
    easeOut(t,t1,t2,posDown,posUp)
    }else if (t < t3){
    posUp
    }else{
    ease(t,t3,t4,posUp,posDown)
    }
    }else
    value

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