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;
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!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
340 People are following this question.
Problem with halt with rotating on y axis
Having projectile face mouse position
Smooth 90 degree rotation on keypress
AI moving Backwards along path
Multiple rotations make a mess!