ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Random motion at intervals > bounce at each interval

FAQ   •   VIEW ALL
 Random motion at intervals > bounce at each interval on Mar 26, 2009 at 2:50:06 pm

I’d like to combine Dan's expression for Random motion at intervals with the Inertial Bounce expression found below. Instead of the bounce occurring at keyframes, I want them to occur at each new Random motion interval.

// Dan's Random Motion at intervals expression
holdTime = .5; //time to hold each position (seconds)
minVal = [0.1*thisComp.width, 0.1*thisComp.height];
maxVal = [0.9*thisComp.width, 0.9*thisComp.height];

seed = Math.floor(time/holdTime);
seedRandom(seed,true);
random(minVal,maxVal)

// Inertial Bounce (moves settle into place after bouncing around a little)
n = 0;
if (numKeys > 0){
n = nearestKey(time).index;
if (key(n).time > time){
n--;
}
}
if (n == 0){
t = 0;
}else{
t = time - key(n).time;
}

if (n > 0){
v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
amp = .05;
freq = 4.0;
decay = 2.0;
value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
value;
}

 Re: Random motion at intervals > bounce at each intervalon Mar 26, 2009 at 11:47:56 pm

Something like this maybe:

holdTime = .5; //time to hold each position (seconds)
t = time - Math.floor(time/holdTime)*holdTime;
minVal = [0.1*thisComp.width, 0.1*thisComp.height];
maxVal = [0.9*thisComp.width, 0.9*thisComp.height];

seed = Math.floor(time/holdTime);
seedRandom(seed,true);
p1 = random(minVal,maxVal);

seedRandom(seed-1,true);
p0 = random(minVal,maxVal);

v = p1 - p0;
amp = .05;
freq = 4.0;
decay = 2.0;
p1 + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

Dan