Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Inertial bounce multiple times on the same property?

Community Beginner ,
Feb 13, 2023 Feb 13, 2023

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;

}

TOPICS
Expressions , Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2023 Feb 13, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2023 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2023 Feb 25, 2023

And what you've pointed me at does what I initially asked. So apologies for that. 
In terms of details on my project: It's basically a bouncing ball in a vertical pinball machine. The ball bounces against a lot of objects and I'm using path animations. With this, I was hoping to get very precise control over bounciness. 
So for example when the ball goes up and hits a panel I'm using a path animation to do squash and stretch, but later on, I still want to use the expression to make the ball just bounce on different surfaces just using the expressions. 
For this, I'm animating both path position and object position and at times I want to stop the expression when keyframing a new position and restart it at a different time with different settings applied to amplitude, frequency & decay.

Sorry for the poor drawing skills but, image attached 


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 13, 2023 Feb 13, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2023 Feb 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 



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2023 Feb 25, 2023
LATEST

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines