- Home /
What is the proper use of AddClip and SetCurve? weird Quaternion error
Hi,
I'm trying 2 different ways to dynamically create an animation and set keyframes (for my current bone rotations) using AddClip and SetCurve.
I am trying this 2 different ways - in my example from my Update() function here, the left mouse button trys it the way I would think it should work: create keys add keys to a curve add curve to the clip and then play that clip. It doesn't work.
The second example here on right click does work but gives me a Quaternion error:
Quaternion To Matrix conversion failed because input Quaternion is invalid { -1.#IND00, -1.#IND00, -1.#IND00, -1.#IND00}
Like so:
if (Input.GetMouseButtonDown(0)) { CharacterToControl.animation.Stop();
AnimationCurve myCurve = new AnimationCurve();
Keyframe key1 = new Keyframe(0, 45.0f);
myCurve.AddKey(key1);
AnimationClip lastPoseClip = new AnimationClip();
lastPoseClip.SetCurve("Root/Left_Sacrum/Left_Hip",typeof(Transform),"localRotation.x", myCurve);
CharacterToControl.animation.AddClip(lastPoseClip, "LASTPOSE");
CharacterToControl.animation.Play("LASTPOSE");
}
if (Input.GetMouseButtonDown(1))
{
CharacterToControl.animation.Stop();
AnimationClip lastPoseClip = new AnimationClip();
lastPoseClip.SetCurve("Root/Left_Sacrum/Left_Hip",typeof(Transform),"localRotation.x",AnimationCurve.Linear(0.0f,45.0f, 0.0f, 45.0f));
CharacterToControl.animation.AddClip(lastPoseClip, "LASTPOSE");
CharacterToControl.animation.Play("LASTPOSE");
}
Which way is correct? Thanks for your help. I'm finding the docs a bit unclear.
(Btw ideally what this is for is to save all the current bone rotations of a character and save them to an animation so I can then blend this with a precanned animation already in the FBX - I've been told that it is not possible to use Animation.Blend or .Crossfade to blend a procedural pose to the start of an animation and that creating a new animation on the fly and then blending is the way to do what i want.)
Thanks for any help :)