- Home /
How can I convert AnimationCurve.in/outTangent to an angle
I need to convert the tangents of a keyframe to angles for a custom animation panel I'm developing. Any help appreciated. I can't seem to find a correlation between the tangent (in or out) and the angle used to display the tangent handles in the standard animation panel / animation curve editor.
Thanks
Answer by MaDDoX · Jul 23, 2012 at 10:31 PM
The angle is calculated counter-clockwise, based on the tangent of the provided float like Bunny83 said - so a simple Mathf.atan should suffice. If you're trying to emulate "step" tangents, you're out of luck, even a value of 0 for the first key's out-tangent and 6000 (or -6000) for the second key's in-tangent won't work the same as what Unity does in its own animation window. My suggestion in this case is to simply add an auxiliary keyframe with a high fractional time value, close to the second keyframe. So you'd have something like this:
var key = new Keyframe (0, 0, 0, 0);
var auxkey = new Keyframe (0.9999, 0, 0, 0);
var key2 = new Keyframe (1, 1, 0, 0);
Unity doesn't care about anything after the fourth decimal, so this would probably work. Good luck!
Answer by Bunny83 · Feb 20, 2011 at 11:15 PM
Well, i just thought the tangents were in degrees when i look at the samples but it's just the tangens of that angle. I copied the sample from Keyframe.inTangent and tried some values. Just make only two keyframes, set the second inTangent to "1" and run the game. Open the curveeditor for the generated curve. If you zoom in properly you will see the tangent have 45. tan(45) == 1.0f
Since you can zoom both axis independently the viewed angle changes. To zoom use the mouse wheel. To zoom x-axis only hold CTRL, to zoom y-axis only hold SHIFT. When you bring both axis to the same scale it will show the actual angle (according to the tangens value).
I'm quite happy with the built in curve editor but if you think you can improve it or if you need some special treatment, go on.
If you need more help just ask, but i guess if you try something like that you know what you're doing ;)
good luck
Your answer
Follow this Question
Related Questions
How can I set my Animation Curve's Tangents to Flat in script? 0 Answers
How can I get an accurate bounding rect for an AnimationCurve 1 Answer
What is the length of the Keyframe tangent? 0 Answers
How do I modify a keyframe/curve's tangent in code? 2 Answers
How do I scale an animation curve by time and value while retaining my tangent values? 0 Answers