Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Move random distance along X, hold, then random distance along Y

  • Move random distance along X, hold, then random distance along Y

    Posted by Andre Ash on March 27, 2017 at 6:14 am

    I’m trying to get null to move randomly following a grid. That is; it can only move up, down, left or right at any one time.

    I’d like it to move, stop, then change direction and move again.

    The length of the move would be set to a random distance with a min/max.

    I’ll then be adding a tracer to the null.

    Andre Ash replied 9 years, 5 months ago 1 Member · 2 Replies
  • 2 Replies
  • Andre Ash

    March 27, 2017 at 6:22 am

    I think I found it

    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]
    }

  • Andre Ash

    March 27, 2017 at 6:24 am

    As always, it was thanks to Dan.

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