Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move layer by random amount over time interval

  • Move layer by random amount over time interval

    Posted by Justin Crowell on October 28, 2024 at 6:58 pm

    Hi all,

    Looking to write an expression that:

    – moves a layer by a small amount every 15 frames.

    – movement lasts 5 frames

    – it shouldn’t jump around–just a single move from point a to point b

    – the movement should be different each time.

    I started by building an array of random numbers, with the goal of basically saying:

    Start at point A. Point B will equal point A times the random number, determined by how many iterations we have gone through.

    But I’m struggling to put this all together.

    Would love your thoughts!

    Thanks!

    Justin Crowell replied 1 year, 5 months ago 2 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    October 28, 2024 at 7:16 pm

    Do you want the movement constrained to a particular area, or each movement constrained to a maximum amount from the previous location?

  • Dan Ebberts

    October 28, 2024 at 8:07 pm

    OK, here’s an example that will wander around in the vicinity of the layer’s original position:

    moveFrames = 15;
    range = 200;
    moveDur = framesToTime(moveFrames);
    seed = Math.floor(time/moveDur);
    t = time%moveDur;
    seedRandom(seed,true);
    offset1 = seed > 0 ? random([-range,-range],[range,range]) : [0,0];
    p1 = value + offset1;
    seedRandom(seed+1,true);
    offset2 = random([-range,-range],[range,range]);
    p2 = value + offset2;
    linear(t,0,moveDur,p1,p2) // could use ease() instead
  • Justin Crowell

    October 28, 2024 at 8:55 pm

    Thanks so much Dan! And yes, definitely want the motion to all occur around the same position.

    The only issue here is that I need the object to move for 5 frames, pause for 15, and repeat.

  • Dan Ebberts

    October 28, 2024 at 9:08 pm

    Ah, that would be like this:

    moveFrames = 5;
    holdFrames = 15;
    range = 200;
    moveDur = framesToTime(moveFrames);
    totalDur = framesToTime(moveFrames+holdFrames);
    seed = Math.floor(time/totalDur);
    t = time%totalDur;
    seedRandom(seed,true);
    offset1 = seed > 0 ? random([-range,-range],[range,range]) : [0,0];
    p1 = value + offset1;
    seedRandom(seed+1,true);
    offset2 = random([-range,-range],[range,range]);
    p2 = value + offset2;
    linear(t,0,moveDur,p1,p2)
  • Justin Crowell

    October 28, 2024 at 9:49 pm

    This is amazing! Thank you so much, Dan!

  • Justin Crowell

    November 7, 2024 at 10:15 pm

    Hey Dan,

    The expression works great–but it looks like it has sort of a hitch at around 4 seconds (video attached). IF it helps, I’m working in 23.98.

    Thanks again for the help!

  • Dan Ebberts

    November 8, 2024 at 12:20 am

    That’s interesting and strange. See if this makes it any better:

    moveFrames = 5;
    holdFrames = 15;
    range = 200;
    moveDur = framesToTime(moveFrames);
    totalDur = framesToTime(moveFrames+holdFrames);
    seed = Math.floor(time/totalDur);
    t = time - seed*totalDur;
    seedRandom(seed,true);
    offset1 = seed > 0 ? random([-range,-range],[range,range]) : [0,0];
    p1 = value + offset1;
    seedRandom(seed+1,true);
    offset2 = random([-range,-range],[range,range]);
    p2 = value + offset2;
    linear(t,0,moveDur,p1,p2)
  • Justin Crowell

    November 8, 2024 at 8:54 pm

    Thanks again, Dan! We actually adjusted the gap to 14 frames for now and that seemed to fix it, but I will check this one out as well. Appreciate your time.

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