ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Changes more than one keyframes value with expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tepi K Agung
Changes more than one keyframes value with expression
on Nov 5, 2019 at 4:27:28 am

Hi!
i have 4 animation keyframes on my timeline, with value like this:
keyframe 1 = 0
keyframe 2 = custom with slider
keyframe 3 = custom with slider
keyframe 4 = 0

and i found this script but only can change 1 keyframe, but i need to change 2 keyframes (key 2&3)
any tips to tweak this script?

thanks for the reply :)

keyNumToChange = 2; //change this - the key num to change(numbering starts at 1)
newVal = [x,value[1]]; //change this - the new position.
target = transform.position;
//-------
nearKey = target.nearestKey(time).index;
lastKey =(target.key(nearKey).time>time) ?((nearKey>1) ? nearKey-1 : nearKey) : nearKey;
nextKey =(lastKey<target.numKeys) ? lastKey+1 : lastKey;
nextVal =target.key(nextKey).value;
lastVal = target.key(lastKey).value;

if(nextKey == keyNumToChange) {
xRatio =((nextVal[0]-lastVal[0]) != 0) ?((target.value[0]-lastVal[0]) /(nextVal[0] -lastVal[0])) : 1;
xVal = lastVal[0]+(newVal[0]-lastVal[0])*xRatio;
yRatio =((nextVal[1]-lastVal[1]) != 0) ?((target.value[1]-lastVal[1]) /(nextVal[1] -lastVal[1])) : 1;
yVal = lastVal[1]+(newVal[1]-lastVal[1])*xRatio;
[xVal, yVal];
} else if(lastKey == keyNumToChange) {
xRatio =((nextVal[0]-lastVal[0]) != 0) ?((target.value[0]-lastVal[0]) /(lastVal[0] -nextVal[0])) : 1;
xVal = newVal[0]+(newVal[0]-nextVal[0])*xRatio;
yRatio =((nextVal[1]-lastVal[1]) != 0) ?((target.value[1]-lastVal[1]) /(lastVal[1] -nextVal[1])) : 1;
yVal = newVal[1]+(newVal[1]-nextVal[1])*xRatio;
[xVal, yVal];
} else {
value;
}


Return to posts index

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