下面是一个简单的 AE 弹跳表达式:

amp = 0.2; // 弹跳高度系数
freq = 2.0; // 弹跳频率
decay = 5.0; // 弹跳衰减系数

n = 0;
if (numKeys > 0){
    n = nearestKey(time).index;
    if (key(n).time > time){
        n--;
    }
}

if (n == 0){
    t = 0;
}else{
    t = time - key(n).time;
}

if (n > 0 && t < 1/freq){
    v = velocityAtTime(key(n).time - thisComp.frameDuration/10);
    value + v*amp*Math.sin(freq*t*2*Math.PI)/Math.exp(decay*t);
}else{
    value;
}

这个表达式可以将一个图层制作成弹性的效果,让它像球一样弹起来。其中,'amp' 表示弹跳的高度系数,'freq' 表示弹跳的频率,'decay' 表示弹跳的衰减系数。在表达式中,首先通过 nearestKey() 函数找到当前时间的最近关键帧,然后计算相对于该关键帧的时间 't'。如果 't' 小于 1/freq,则使用 velocityAtTime() 函数获取关键帧前一帧的速度 'v',然后将当前值加上弹跳的偏移量。如果 't' 大于 1/freq,则直接返回当前值。

AE 弹跳表达式:让你的图层像球一样弹起来