Animations in my game are stored as a series of keyframes and I use linear interpolation to tween between them when running them on a character - but linear interpolation either makes the animator use extra of keyframes (harder for them (me in this case)) or looks jerky.
I'd like to smoothly tween between the values, but I can't figure out an algorithm for this.
My terms:
My linear interpolation algorithm:
I've been trying to think of ways to smooth this, taking into account the keyframes before and after low and high, time[lowIdx - 1] and time[highIdx + 1] but I haven't come up with anything that works.
What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this :D
I'd like to smoothly tween between the values, but I can't figure out an algorithm for this.
My terms:
time[] 'is the array of keyframe times value[] 'is the array of keyframe values t# 'is the time I want a value for lowIdx 'is the index of the closest keyframe lower than t highIdx 'is the index of the closest keyframe higher than t rLowHigh# 'is the ratio of the distance of t from time[lowIdx] relative to the distance between time[highIdx] - time[lowIdx] vLowHigh# 'is the value from linear interpolation between value[lowIdx] and value[highIdx]
My linear interpolation algorithm:
rLowHigh# = (t - time[lowIdx]) / (time[highIdx] - time[lowIdx]) vLowHigh# = value[lowIdx] + (value[highIdx] - value[lowIdx]) * rLowHigh
I've been trying to think of ways to smooth this, taking into account the keyframes before and after low and high, time[lowIdx - 1] and time[highIdx + 1] but I haven't come up with anything that works.
What algorithms do you use that are smoother looking than linear interpolation? I'd really love to fix this :D