Skip to main content
Participating Frequently
February 14, 2023
Question

Inertial bounce multiple times on the same property?

  • February 14, 2023
  • 2 replies
  • 1175 views

What I'm trying to do is basically move, bounce, move, bounce, etc

I don't want to use multiple nulls with the expression added to control separate bounces.
So,  I'm trying to learn how to trigger this at a certain time instead of the last keyframe. 

So far no matter where I've searched, no one seems to talk about how to trigger this at a certain time, stop it and run it again at the indicated time. 
If anyone could help me understand how to do this it would be greatly appreciated. 

 

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 && t < 1){

v = velocityAtTime(key(n).time - thisComp.frameDuration/10);

amp = .05;

freq = 4.0;

decay = 8.0;

value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);

}else{

value;

}

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
February 14, 2023

It may just be a matter of having a pair of matching keyframes delineating each period where you want the layer to (I'm assuming) sit and bounce as a result of the previous movement,  before moving on to the next location and bouncing there.

AM_01Author
Participating Frequently
February 25, 2023

First of all, thanks for all your work teaching these things. Without it, I'd be nowhere. 
I know it might be a case of learning more coding and perhaps the answer is obviously staring at me 🙂 
And, yes, that's precisely what I don't get how to do. How do I do exactly what you just said? 

To explain this better as I think my initial question was lacking: I want to assign different values to the amplitude, frequency & decay for different keyframe pairs. 
The way I was thinking was to do either "run this expression at time"/ "stop at time" 
or 
Replacing "nearestKey" with some form of "inTime" / "start at time"

Hope I'm making sense...
Thanks 



Dan Ebberts
Community Expert
Community Expert
February 25, 2023

I guess you could set up arrays for amplitude, frequency and decay, with an entry for each keyframe, and then use n-1 to index into the arrays. So it might end up looking like this:

 

amp   = [ 0.0,  .05,  0.0,  .05,  0.0,  .05,  0.0,  .05,  0.0];
freq  = [ 4.0,  4.0,  4.0,  4.0,  4.0,  4.0,  4.0,  4.0,  4.0];
decay = [ 8.0,  8.0,  8.0,  8.0,  8.0,  8.0,  8.0,  8.0,  8.0];
n = 0;
val = value;
if (numKeys > 0){
  n = nearestKey(time).index;
  if (key(n).time > time) n--;
}
t = n ==0 ? 0 : time - key(n).time;

if (n > 0 && t < 1){
  v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
  i = Math.min(n-1,amp.length-1);
  val = value + v*amp[i]*Math.sin(freq[i]*t*2*Math.PI)/Math.exp(decay[i]*t);
}
val

 

Mylenium
Legend
February 14, 2023

All you need to know:

 

http://www.motionscript.com/articles/bounce-and-overshoot.html

 

Otherwise you have to provide more info on your project.

 

Mylenium

AM_01Author
Participating Frequently
February 25, 2023

Thank you for your answer. I've learned what I know from Dan's website but I do feel like I'm missing something.