-
valueAtTime in both directions
Hi folks,
let’s say I have a keyframed animation that goes from 0 to -500 in Z space and back to 0 again and a layer that references that with valueAtTime and a -.1 delay.
I want the delay to adapt to the change of direction, which works with this code:
src=thisComp.layer(index-1)
v=src.transform.position.velocity;
let delay;
if(v[2] >= 0) {delay = -.1} else {delay = .1};
src.transform.position.valueAtTime(time-delay);
Unfortunately, this generates two problems:
- On the first frame of the animation, which starts in the beginning of the comp, the position value jumps to -107.8, while it should be 0 since the animation it references is at 0 as well.
- One frame before the -500 keyframe and the direction switch, the delayed layers jump values, which makes it look choppy like a few frames have been skipped, due to the nature of the adaptive delay, which switches values abruptly.
This code fixes the first problem:
const src=thisComp.layer(index-1);
const v = src.transform.position.velocity;
let delay;
if (time == 0){
[value[0],value[1],value[2]];
}else{
(v[2] >= 0) ? delay = -.1 : delay = .1;
src.transform.position.valueAtTime(time-delay);
};
…but the other persists.
Any help would be fantastic 🙂