ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

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

FAQ   •   VIEW ALL
 Move random distance along X, hold, then random distance along Y on Mar 27, 2017 at 6:14:31 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.

 Re: Move random distance along X, hold, then random distance along Yon Mar 27, 2017 at 6:22:56 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 &lt; p1){ ease(time,start,p1,[startX,startY],[endX,startY]) }else if (time &lt; p2){ [endX,startY] }else if (time &lt; p3){ ease(time,p2,p3,[endX,startY],[endX,endY]) }else{ [endX,endY] } ```