Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Change Random Motion To Specific Postion

  • Change Random Motion To Specific Postion

    Posted by D_beacon on September 20, 2007 at 3:07 pm

    Hey guys.

    I’m currently producing a nifty little background with squares flying round the screen in random motion. My problem is that after 35 secs I need the squares to go to specific positions on the screen.

    This is the code I have used to do the random motion gained from the awesome Motionscript.com inserted into the position property:

    segDur = 12;// duration of each “segment” of random motion
    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);

    What I have been trying to do is add a couple of lines of code that says whilst the time is less than 35secs use the random motion code, after 35secs move into your final position.

    Neil Floyd replied 14 years ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    September 20, 2007 at 4:33 pm

    Play around with this – after 35 seconds of random motion, it will slide into “finalPos” over a 1 second transition period.

    finalPos = [100,100];
    maxTime = 35;
    transitionTime = 1;

    segDur = 12;// duration of each “segment” of random motion
    minVal = [0.1*thisComp.width, 0.1*thisComp.height];
    maxVal = [0.9*thisComp.width, 0.9*thisComp.height];

    t = Math.min(time, maxTime);
    seed = Math.floor(t/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = random(minVal,maxVal);
    seedRandom(seed+1,true);
    endVal = random(minVal,maxVal);
    randPos = ease(t,segStart,segStart + segDur, startVal, endVal);

    ease(time,maxTime,maxTime + transitionTime,randPos,finalPos)

    Dan

  • D_beacon

    September 21, 2007 at 7:25 am

    Thanks So much Dan

    I had been playing around with an If statement, but this is such a simpler way to do it. It works beautifully.

  • Neil Floyd

    September 14, 2012 at 11:49 am

    I know this is an old post but I had a question with it. I love this expression and it works perfectly. What if you wanted it to start at an initial point and then be random? You can use the same time as in this example. Let’s say I want it to start at [100,100] at 35 sec and then be random.

    Also if you can have a start point, then random and then back to the same start point so the loop is clean. Thanks for your help

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