Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Every X seconds, move in a random direcition.

Tagged: 

  • Every X seconds, move in a random direcition.

    Posted by Dan Thompson on September 27, 2020 at 9:00 pm

    I’m looking for an expression that will move my layer a certain amount in a random direction every few seconds.

    The key here is that the layer needs to stay still between each movement, for a duration of my choosing.

    I’ve looked online and only found similar expressions, however my AE skills are pretty much zero so I wasn’t unable to edit them to my desired results even after a couple of hours of trying.

    Thanks a lot!

    Dan Thompson replied 5 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • Scott Mcgee

    September 28, 2020 at 8:00 am

    This will help you get started

    segDur = 1;

    minVal = [0.1*thisComp.width, 0.1*thisComp.height];

    maxVal = [0.9*thisComp.width, 0.9*thisComp.height];

    seed = Math.floor(time/segDur);

    segStart = seed*segDur;

    seedRandom(seed,true);

    startVal = random(minVal,maxVal);

    seedRandom(seed+1,true);

    endVal = random(minVal,maxVal);

    ease(time,segStart,segStart + segDur, startVal, endVal);

    This was by Dan Ebberts from his website here https://motionscript.com/mastering-expressions/random-1.html

    As for the pause in the middle. I don’t have time to write some up, but you should be able to add a delay between each movement.

    Hope this steers you in the right direction.

  • Dan Thompson

    September 28, 2020 at 12:44 pm

    Thanks! I’ve already found this guy’s expression for random movement, but like you said it doesn’t have the pauses.

    I’ve tried for hours to add pauses but I’m failing to even get a clue on the very basics.

    If anyone can still help that’ll be great 🙂

  • Dan Ebberts

    September 28, 2020 at 2:14 pm

    Something like this maybe:

    moveDur = .5;

    holdDur = 2;

    segDur = moveDur+holdDur;

    minVal = [0.1*thisComp.width, 0.1*thisComp.height];

    maxVal = [0.9*thisComp.width, 0.9*thisComp.height];

    seed = Math.floor(time/segDur);

    segStart = seed*segDur;

    seedRandom(seed,true);

    startVal = random(minVal,maxVal);

    seedRandom(seed+1,true);

    endVal = random(minVal,maxVal);

    ease(time,segStart,segStart + moveDur, startVal, endVal);

  • Dan Thompson

    September 28, 2020 at 3:00 pm

    That’s great! Thank you so much!

    The only question I have now is which parameter can I edit in order to increase the minimum travel distance?

    EDIT: Adding a multiplier to startVal and endVal seems to help, but it sometimes creates a “jump” right before the layer starts moving.

    **Another note, I don’t need any “protection” that prevents the layer from flying out of the canvas, if that matters!

    Thanks again!

  • Dan Thompson

    September 30, 2020 at 2:17 pm

    Alright I got what I wanted and fixed the problem by adding a multiplier to the minVal and maxVal instead!

    Thanks again 😀

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