- Home /
Animationcurve Tangets Smoothing
Hello to All!
i am making an editor tool were i am trying to take information from a touch surface to draw an Animation Curve. The result i have so far look like something like this:
Problem is that i cant find a way to make the tangents smooth on each key.
So my first question is how can i make each key tangent to look towards the direction on the previous and next key. (or any way other to smooth it out)
And Secondly if you know an operation / algorithm that would smooth the curve to the least needed keys...
Thanks in Advance!!
Answer by scanzy · Jun 02, 2017 at 02:05 PM
You can call AnimationUtility.SetKeyRightTangentMode and SetKeyLeftTangentMode
, setting TangentMode.Auto
to make it recalculate tangent on that key:
//c# code:
for (int i = 0; i < yourCurve.keys.Length; i++)
{
AnimationUtility.SetKeyLeftTangentMode (yourCurve, i, AnimationUtility.TangentMode.Auto);
AnimationUtility.SetKeyRightTangentMode(yourCurve, i, AnimationUtility.TangentMode.Auto);
}
Note that AnimationUtility
belongs to UnityEditor
namespace, so this is avaliable only in editor
Your answer
![](https://koobas.hobune.stream/wayback/20220613181254im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Issues with AnimationCurves 0 Answers
Mark gameobject field as changed from prefab 2 Answers
Custom Inspector: Accessing a reference to another MonoBehaviour? 1 Answer
Unity inspector scripting - scriptable objects - card game 0 Answers
How to properly handle Undo events in custom inspector? 0 Answers