How can I apply easing to a rotation when programmatically creating an AnimationClip?
I'm trying to apply easing to the rotation of an object using the following code. The actual rotation is being applied, but only as a Linear curve (the EaseInOut function call results in a Linear curve). How can I successfully apply easing to the following rotation (z axis rotation only)?
float startTime = 0.0f;
float endTime = 0.12f;
AnimationClip clip = new AnimationClip();
Quaternion quatStart = Quaternion.Euler (new Vector3 (0.0f, 0.0f, 0.0f));
Quaternion quatEnd = Quaternion.Euler (new Vector3 (0.0f, 0.0f, 30.0f));
AnimationCurve curve_rotate_x = new AnimationCurve ();
curve_rotate_x.AddKey (startTime, quatStart.x);
curve_rotate_x.AddKey (endTime, quatEnd.x);
AnimationCurve curve_rotate_y = new AnimationCurve ();
curve_rotate_y.AddKey (startTime, quatStart.y);
curve_rotate_y.AddKey (endTime, quatEnd.y);
// I am only rotating on the z axis.
// This call to EaseInOut results in a Linear curve!
AnimationCurve curve_rotate_z = AnimationCurve.EaseInOut (startTime, quatStart.z, endTime, quatEnd.z);
AnimationCurve curve_rotate_w = new AnimationCurve ();
curve_rotate_w.AddKey (startTime, quatStart.w);
curve_rotate_w.AddKey (endTime, quatEnd.w);
clip.SetCurve ("InnerObj", typeof(Transform), "localRotation.x", curve_rotate_x);
clip.SetCurve ("InnerObj", typeof(Transform), "localRotation.y", curve_rotate_y);
clip.SetCurve ("InnerObj", typeof (Transform), "localRotation.z", curve_rotate_z);
clip.SetCurve ("InnerObj", typeof (Transform), "localRotation.w", curve_rotate_w);
clip.legacy = false;
clip.name = "RotationClip";
clip.wrapMode = WrapMode.Once;
clip.EnsureQuaternionContinuity ();
When I inspect the generated animation curve resulting from my code it looks like this:
I've also tried playing with in and out tangents but to no avail. Any help would be greatly appreciated!
linear-curve.png
(17.5 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612113537im_/https://answers.unity.com/themes/thub/images/avi.jpg)