ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Change Value on Previous Keyframe in Index, not Nearest

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jonathan Moxness
Change Value on Previous Keyframe in Index, not Nearest
on Jul 31, 2020 at 7:04:17 pm

I have an expression on a Null slider ("Magazine control") that I want to add 25 to the value of every time I add a keyframe to another slider on the same Null ("Magazine Reload"). Currently I have it mostly working except it's changing when it's closer to the next keyframe than it is to the previous, and I want it to change only when it hits the next keyframe, not when it's closer, so I need to reference the previous keyframe instead, and I'm not sure how to do that.

Here's my expression currently (applied to the "Magazine control" slider effect):

reload = effect("Magazine Reload")("Slider").nearestKey(time).index;
Math.round(value)+(25*reload);

I found a couple other forum posts referencing previous keyframes in expressions, but I couldn't figure out how to translate them to my problem.

reload = effect("Magazine Reload")("Slider").nearestKey(time).index;
Math.round(value)+(25*reload);


Return to posts index

Dan Ebberts
Re: Change Value on Previous Keyframe in Index, not Nearest
on Jul 31, 2020 at 7:21:49 pm

I haven't tested it, but it should be like this:

reload = effect("Magazine Reload")("Slider").nearestKey(time).index;
if (time < effect("Magazine Reload")("Slider").key(reload).time) reload--;
Math.round(value)+(25*reload);


Dan



Return to posts index

Jonathan Moxness
Re: Change Value on Previous Keyframe in Index, not Nearest
on Jul 31, 2020 at 7:56:27 pm

Thank you so much Dan! Works perfect!


Return to posts index

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