ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Adding decay that clamps at a certain value without altering subsequent animations

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Danny Perry
Adding decay that clamps at a certain value without altering subsequent animations
on Mar 6, 2019 at 3:09:20 am

Hello Creative Cow! I have been a long time lurker and am usually able to find solutions to my problems by browsing previous posts, but I have hit a roadblock.

I have been following Dan Ebberts' guide to driving acumulative animation through audio in order for me to mimic Trapcode Sound Keys. I have gotten great results thus far, but I can't figure out the right way to add decay. I currently have my value increasing by x everytime my beat counter detects a beat. X being a slider control for amplitude. I want to add decay so that this number is constantly decaying until it hits the original "size" variable at which point the value stays at that until the next beat which should increase the value by the amplitude.

Dec is constantly increasing with time and when I try to clamp that value to not be less than "size" it has to play catch up with every single beat. This means that if I get to a point where there aren't a lot beats going on in the song the next beat won't actually cause any value changes until part of my expression outputs a value that is > the constantly decreasing decay.

How can I set this up so that the decay stops when it makes the value < "size" and that it won't mess up any subsequent values driven by the beat?

I am very sorry if this isn't clear, describing this stuff is difficult!

size = effect("Size")("Slider");
amp = effect("Amplitude")("Slider");
cnt = effect("Beat Count")("Slider");
dec = (effect("Decay")("Slider")*time);
s = size+((amp*cnt)-dec);
[s,s]


Return to posts index

Kalleheikki Kannisto
Re: Adding decay that clamps at a certain value without altering subsequent animations
on Mar 6, 2019 at 9:20:56 am

You want to tie the decay value to the time value of the last beat. If there are no keyframes, you will have to look backwards frame by frame with a loop until you find the point where the beat count changes. That gives you the time of the last beat, and you would use that as the start time for the decay, i.e. decay would be zero at that point and increase based on your decay rate and time elapsed between that time and current time. To stop the decay at a given value, you can use a Math.max() expression.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Danny Perry
Re: Adding decay that clamps at a certain value without altering subsequent animations
on Mar 6, 2019 at 3:31:36 pm

Ahh I see. I currently have the "cnt" variable increasing with every beat. Is there a way to find the time when that value changes and then start the decay from there?


Return to posts index


Kalleheikki Kannisto
Re: Adding decay that clamps at a certain value without altering subsequent animations
on Mar 6, 2019 at 7:17:34 pm

Yes, that requires a while loop that looks backwards from current time frame by frame until it finds the frame where the value is different from the current frame.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Danny Perry
Re: Adding decay that clamps at a certain value without altering subsequent animations
on Mar 6, 2019 at 9:07:59 pm

Do you happen to know how that expression would look? Sorry, this is a little out of my element 🙃


Return to posts index

Kalleheikki Kannisto
Re: Adding decay that clamps at a certain value without altering subsequent animations
on Mar 7, 2019 at 7:37:01 am

This is sort of from the top of my head, so might not be exactly right.

changepointframe == 0;
for (i = timeToFrames(time); i <= timeToFrames(inPoint); i--){
if (effect("Beat Count")("Slider").valueAtTime(i*thisComp.frameDuration)<cnt){
changepointframe = i;
break
}
}


What it is meant to do is look backwards from the current time frame by frame until the beat count slider goes smaller than the value of the variable cnt (which is the value of the slider at current time), and when it finds that point, it ends the loop, assigning that frame number to the variable changepointframe.

If you multiply with frame duration (changepointframe*thisComp.frameduration), it gives you the time where the decay should start.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]