- Home /
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!
Answer by Bunny83 · May 06, 2013 at 02:34 PM
No, they use cubic bezier curves for each segment ;) 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 ;)
$$anonymous$$eep in $$anonymous$$d that the equatation for a cubic bezier and a hermite spline are quite similar (like explained in the page you linked in your question). If i find the time i will post some code how to interpolate between two $$anonymous$$eyFrames
That would be awesome if you could make a quick example. The only thing I'm really interested in is how to make the 1 dimensional in/outTangent into a 2D point. I've struggled all day and is going crazy ;)
Answer by mikaelemtinger · May 06, 2013 at 06:46 PM
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;
Your answer
