How to interprete Keyframe.inTangent and .outTangent values

I’m need to interpolate some values between two Keyframes and I’m positive Unity is using Hermite interpolation as described here…

http://cubic.org/docs/hermite.htm

I’m guessing…

P1 = keys[ 0 ].value;
P2 = keys[ 1 ].value;

…but if I set…

T1 = keys[ 0 ].outTangent;
T2 = keys[ 1 ].inTangent;

…the interpolation looks OKish but doesn’t reach the extremes of my curves. So I’m guessing I need to do something to the tangents before throwing them into the equation.

Thanks!

No, they use cubic bezier curves for each segment :wink: The in and out tangent is the tangent of the desired angle and not an angle in degree or radians like the documentation suggests.

See this question for more details :wink:

I found the solution, you need to scale the inTangent and outTangent with the delta time between the two keys. So, if you like to interpolate the value this is how (for H1 H2 H3 H4, see link in question):

deltaTime = keys[ 1 ].time - keys[ 0 ].time;
interpolatedValue = H1 * keys[ 0 ].value + H2 * keys[ 1 ].value + H3 * keys[ 0 ].outTangent * deltaTime + H4 * keys[ 1 ].inTangent * deltaTime;