Skip to main content
frankiej123
Known Participant
November 5, 2022
Question

Expression Help: Running Expression after Keyframes

  • November 5, 2022
  • 2 replies
  • 228 views

Hey,

Whats the best way to adapt Dans oscillation script to run it after 2 keyframes that change opacity from 0-100 (basically making layer appear then oscillate opacity). Just been using a separate Transform currently but wondered if there was a way to run an expression only after the last keyframe?

//Dan's Oscillation Script

minVal = 20;
maxVal = 100;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2
avgVal + amp*(Math.sin(time*freq*Math.PI*2))
This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
November 5, 2022

You could try this:

if (numKeys > 1 && time >= key(numKeys).time){
  t = time - key(numKeys).time;
  minVal = 20;
  maxVal = key(numKeys).value;
  freq = 1; // oscillations per second
  avgVal = (minVal + maxVal)/2;
  amp = (maxVal - minVal)/2;
  avgVal + amp*(Math.cos(t*freq*Math.PI*2));
}else{
  value;
}
Inspiring
November 5, 2022
minVal = 20;
maxVal = 100;
freq = 1; // oscillations per second
avgVal = (minVal + maxVal)/2;
amp = (maxVal - minVal)/2;
result = avgVal + amp*(Math.sin(time*freq*Math.PI*2));

//linear(time, key(2).time, key(2).time+1, value, result);
result = result * (value/100);

 

Here are a couple of options. Comment out the other last line to try each. 

 

The linear one uses time to control a fade from the keyframed values to the oscillating result, from the time of the second keyframe to 1 second after. So this will do a clean fade up then transition to the oscillation.

The other just multiples the oscillation result by 0 > 1 as you increase the opacity to 100, so it oscillates through the fade up too.

You could just use an if (time > key(2).time) result else value; but that would abruptly switch to whatever the oscillating value is on the frame after the keyframe