FORUMS: list search recent posts

# Changing expression values based on time

FAQ   •   VIEW ALL
 Changing expression values based on time on Jul 21, 2014 at 10:21:39 pm

Hello,

Long time troller, first-time post. I recently started learning about expressions and I've run into a brick wall when it comes to changing the values of an expression based on where the player head is in the timeline. Currently I am currently trying to hack the "inertial bounce" script so that I can change specific values (amp, freq, decay) during the movie. Here's the basic sequence:

1. Movie starts at t=0, nothing on stage
2. At t=5, a shape layer animates into the viewport from the bottom. I've set the inertial bounce script to have a lot of bounce, and it works fine
3. At t=45, I want the same shape layer to animate it's position to the right about 100px. However, I don't want it to have the same amount of bounce as in step 2

It looks like I can only assign one expression per shape, so I need to add some logic that basically says, "If time is less than 45, make the bounce big. If time is greater than 45, don't have any bounce."

I tried to use a simple if/else to change the "amp" value, but I don't notice any difference (see below). Note that I'm hoping to change the value at multiple times during the movie, for instance it would be great if I could change the "amp" value 3-4 times during the course of the movie, not just once. Apologies if this is just a simple coding error, but any help would be greatly appreciated. Thank you in advance!

Here's where I got the original script:
http://www.graymachine.com/blog/my-top-expressions

``` if (time &lt; 40) { amp = .05; } else if (time > 40) { amp = 1.0; } else { amp = 0.05; } freq = 2.0; decay = 7.0; 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 &lt; 1){ v = velocityAtTime(key(n).time - thisComp.frameDuration/10); value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t); }else{ value }```

 Re: Changing expression values based on timeon Jul 22, 2014 at 1:23:22 am

Please don't be offended, but I just want to make sure you understand that your t values represent seconds, not frames. Is that what you intended (i.e. the second amplitude value kicks in at 40 seconds)?

Dan

 Re: Changing expression values based on timeon Jul 22, 2014 at 2:59:05 am

One other thing I should add, is if the reason you want to change the amplitude is to make overshoot better match a change in keyframed velocity, you should consider this version that will automatically match the overshoot to the incoming velocity:

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

Dan