Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › Random Movement Expression

  • Random Movement Expression

    Posted by Curses on March 20, 2007 at 1:30 am

    Hello, alright so I’m looking for some help with the popular random movement expression. – I would like the object to not be random in the beginning, so it starts out as a shape, then they all move out of place randomly, is there maybe a easier way to do this besides a expression? or can I make this expression work? basically I just need to set a starting X,Y coordinate… possible right?

    —————–start——————
    origin = [10,10]; //upper left hand corner of grid
    dimX = 8; //number of columns
    dimY = 6; //number of rows
    gap = 20; // distance between cells (pixels)
    gridRate = 300; //speed (pixels per second)
    holdTime = .2; //(seconds)

    end = 0;
    j = 0;

    while (time >= end){
    seedRandom(j,true);
    startX = Math.floor(random(dimX))*gap + origin[0];
    startY = Math.floor(random(dimY))*gap + origin[1];
    j +=1;
    seedRandom(j,true)
    start = end;
    endX = Math.floor(random(dimX))*gap + origin[0];
    endY = Math.floor(random(dimY))*gap + origin[1];
    deltaX = Math.abs(endX – startX);
    deltaY = Math.abs(endY – startY);

    end += (deltaX + deltaY)/gridRate + 2*holdTime;
    }

    p1 = start + deltaX/gridRate;
    p2 = p1 + holdTime;
    p3 = p2 + deltaY/gridRate;

    if (time < p1){ ease(time,start,p1,[startX,startY],[endX,startY]) }else if (time < p2){ [endX,startY] }else if (time < p3){ ease(time,p2,p3,[endX,startY],[endX,endY]) }else{ [endX,endY] } -------------------------end--------------------------

    Dan Ebberts replied 19 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    March 20, 2007 at 2:51 am

    Ah, the old random motion on a grid expression. So you want the objects to start out as an array that form a picture and at some point break into random grid motion, is that correct? If so, do the pieces fill the grid or is the grid bigger? If the grid is bigger, are the pieces arranged at the center? Or is it something else entirely?

    Dan

  • Curses

    March 20, 2007 at 8:51 am

    Well, i either want it to form the final object, or start with the final object and break apart, from there i can either reverse the time or do anything i want with it, just at 1 point it needs to be on the final object.

  • Dan Ebberts

    March 20, 2007 at 1:59 pm

    If you make a small change to the expression, the pieces will start from wherever you place them:

    
    origin = [10,10]; //upper left hand corner of grid
    dimX = 8; //number of columns
    dimY = 6; //number of rows
    gap = 20; // distance between cells (pixels)
    gridRate = 300; //speed (pixels per second)
    holdTime = .2; //(seconds)
    
    end = 0;
    j = 0;
    
    while (time >= end){
      seedRandom(j,true);
      
      startX = Math.floor(random(dimX))*gap + origin[0];
      startY = Math.floor(random(dimY))*gap + origin[1];
      if (j == 0){
        startX = value[0];
        startY = value[1];
      }
      j +=1;
      seedRandom(j,true)
      start = end;
      endX = Math.floor(random(dimX))*gap + origin[0];
      endY = Math.floor(random(dimY))*gap + origin[1];
      deltaX = Math.abs(endX - startX);
      deltaY = Math.abs(endY - startY);
    
      end += (deltaX + deltaY)/gridRate + 2*holdTime;
    }
    
    p1 = start + deltaX/gridRate;
    p2 = p1 + holdTime;
    p3 = p2 + deltaY/gridRate;
    
    if (time < p1){
      ease(time,start,p1,[startX,startY],[endX,startY])
    }else if (time < p2){
      [endX,startY]
    }else if (time < p3){
      ease(time,p2,p3,[endX,startY],[endX,endY])
    }else{
      [endX,endY]
    }
    
    
    

    Dan

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