Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions play keyframes at random time

  • play keyframes at random time

    Posted by Marc Rühl on March 17, 2017 at 5:20 pm

    I have a layer with some scale keyframes. Now I would like to loop this animation BUT with a random pause between the loops.
    Since it would great if the loop also switches it’s position with every loop I thought it would be a good idea to have an independant value, which could be read from the position and the scale expression.
    Maybe something like a slider which randomly switches from 0 to 1, to make the position change and start the loop again.
    This would then be the expression for this slider

    But I’m still not sure if this is really the way to go, since I’m having a hard time figuring out the expression for position and the scale keyframes.

    segMin = .5; //minimum segment duration
    segMax = 2.5; //maximum segment duration
    Dur = .05;

    end = 0;
    j = 0;
    while ( time >= end){
    j += 1;
    seedRandom(j,true);
    start = end;
    end += random(segMin,segMax);
    }
    if (time > end - Dur){
    1;
    }else{
    0
    }

    http://www.schwarzgrau.com

    Marc Rühl replied 9 years, 1 month ago 1 Member · 2 Replies
  • 2 Replies
  • Marc Rühl

    March 20, 2017 at 12:24 pm

    I used one of Dan Ebberts Random Motion scripts to figure out the first part of this expression construction. I thought I should share it, since maybe someone else could find it helpful.
    This expression will loop the existing keyframes of this property in a random timespan of 1 to 5 seconds.

    PSEmin = 1;
    PSEmax = 5;

    end = 0;
    j = 0;
    while ( time >= end){
    j += 1;
    seedRandom(j,true);
    start = end;
    end += random(PSEmin,PSEmax);
    }

    MT = time - start;

    valueAtTime(MT);

    http://www.schwarzgrau.com

  • Marc Rühl

    March 20, 2017 at 12:56 pm

    So it seems I got everything working. I honestly have no idea if someone will find it useful, but I’ll post it anyways.

    This example layer has a few keyframes on scale and a point control effect applied, which is called timer.
    EXPRESSION 1 does all the magic and is applied on the point control effect. (It’s only a point control to get access to two values)
    EXPRESSION 2 is applied on scale and
    EXPRESSION 3 is applied on position and will make the layer jump to a new position every time the keyframes get “played”

    ------------------------------------------------------
    EXPRESSION 1

    PSEmin = 1;
    PSEmax = 5;

    end = 0;
    j = 0;
    while ( time >= end){
    j += 1;
    seedRandom(j,true);
    start = end;
    end += random(PSEmin,PSEmax);
    }
    [start,end]

    ------------------------------------------------------
    EXPRESSION 2

    start = effect("timer")("Point")[0]
    MT = time - start;

    valueAtTime(MT);

    ------------------------------------------------------
    EXPRESSION 3

    maxX = 600;
    maxY = 600;
    start = effect("timer")("Point")[0]
    seedRandom(start,true);
    Xpos = random(maxX);
    Ypos = random(maxY);
    [Xpos,Ypos]

    http://www.schwarzgrau.com

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