Skip to main content
Known Participant
November 5, 2023
Answered

Increasing the value of a property using markers with linear interpolation

  • November 5, 2023
  • 2 replies
  • 759 views

Hello Community!

 

How can I pimp the following expression with a linear interpolation 5 frames before the marker?

 

 

if (marker.numKeys > 0) {
    nearestMarker = marker.nearestKey(time);
    if (nearestMarker.time > time){
        nearestMarker.index - 1;
    } else {
        nearestMarker.index;
    }
}

 

 

I want to have a smooth transition between the previous and next value 5 frames before the next value.

 

 

Many thanks!

This topic has been closed for replies.
Correct answer Dan Ebberts

Something like this maybe:

 

m = marker;
val = 0;
if(m.numKeys > 0){
  n = m.nearestKey(time).index;
  if (time >= m.key(n).time) n = Math.min(m.numKeys,n+1);
  t = m.key(n).time - time;
  val = linear(t,0,framesToTime(5),n,n-1);
}
val

 

2 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
November 5, 2023

Something like this maybe:

 

m = marker;
val = 0;
if(m.numKeys > 0){
  n = m.nearestKey(time).index;
  if (time >= m.key(n).time) n = Math.min(m.numKeys,n+1);
  t = m.key(n).time - time;
  val = linear(t,0,framesToTime(5),n,n-1);
}
val

 

Mylenium
Legend
November 5, 2023

https://www.motionscript.com/design-guide/marker-sync.html

 

https://www.motionscript.com/design-guide/audio-trigger.html

 

Based on that, you need to use a linear() interpolator to blend between the values. it's not really clear what you want to do, though. If you use a range selector stuff liek the animators interpolation options matter as well and that alone could be sufficient to create the delay without even resorting to expressions.

 

Mylenium

Known Participant
November 5, 2023

Hi @Mylenium. Thank you for your feedback.

 

I would like to achieve exactly what the above expression already does, and that is to increase the value of a property by a whole number at each marker - but with a linear() interpolation --> five frames before the marker.

 

You're right, but in my case,  options do not help. I am familiar with them.

 

Thank you.