- Home /
AnimationCurve created in runtime, unexpected behaviour
Hi, I need some help with this:
Keyframe[] k_x = new Keyframe[len];
Keyframe[] k_y = new Keyframe[len];
Keyframe[] k_z = new Keyframe[len];
Keyframe[] k_qx = new Keyframe[len];
Keyframe[] k_qy = new Keyframe[len];
Keyframe[] k_qz = new Keyframe[len];
Keyframe[] k_qw = new Keyframe[len];
for (int i = 0; i < boneChannel.rotation_key_list.Length; i++)
{
//define "mat" here which is the character bone data.
Vector3 new_vec = mat.GetColumn(3);
Quaternion new_quat = QuaternionFromMatrix(mat);
k_x[i] = new Keyframe(t, new_vec.x, 0f,0f); //defining in and out tangents as 0
k_y[i] = new Keyframe(t, new_vec.y, 0f,0f);
k_z[i] = new Keyframe(t, new_vec.z, 0f,0f);
k_qx[i] = new Keyframe(t, new_quat.x, 0f,0f);
k_qy[i] = new Keyframe(t, new_quat.y, 0f,0f);
k_qz[i] = new Keyframe(t, new_quat.z, 0f,0f);
k_qw[i] = new Keyframe(t, new_quat.w, 0f,0f);
}
curve_pos_x = new AnimationCurve(k_x);
curve_pos_y = new AnimationCurve(k_y);
curve_pos_z = new AnimationCurve(k_z);
curve_quat_x = new AnimationCurve(k_qx);
curve_quat_y = new AnimationCurve(k_qy);
curve_quat_z = new AnimationCurve(k_qz);
curve_quat_w = new AnimationCurve(k_qw);
clip.SetCurve(relative_path, typeof(Transform), "localPosition.x", curve_pos_x);
clip.SetCurve(relative_path, typeof(Transform), "localPosition.y", curve_pos_y);
clip.SetCurve(relative_path, typeof(Transform), "localPosition.z", curve_pos_z);
clip.SetCurve(relative_path, typeof(Transform), "localRotation.x", curve_quat_x);
clip.SetCurve(relative_path, typeof(Transform), "localRotation.y", curve_quat_y);
clip.SetCurve(relative_path, typeof(Transform), "localRotation.z", curve_quat_z);
clip.SetCurve(relative_path, typeof(Transform), "localRotation.w", curve_quat_w);
Now, for just a certain bone, I get this artifacted rotation curves:
I've tried other ways of defining the curve and it's always the same bug...Really don't know what to do. Any thoughts? Thanks in advance.
Does it affect the Evalute's return value ? $$anonymous$$aybe it's just graphic ?
Haven´t tested Evaluate but artifacts are present in the animation, I mean, you see it ingame.
Answer by Zarlang · Jun 05, 2012 at 06:26 PM
Well, an answer to this can be found here. http://forum.unity3d.com/threads/63463-Weird-tangents-at-Keyframe-creation
Answer by Bunny83 · Jun 04, 2012 at 06:31 PM
I think you shouldn't animate the quaternion components the way you did. Usually you animate eulerangles.
It's also not really clear where you get your data from. I see you animate in local space which is correct, but where is your matrix comming from? Is it in local space?
zarlanga : Well, I tried converting quaternion to angles, it's the same problem. Let me try to explain it a bit:
I get, from a file, the rotation and position offset of a bone in a certain keyframe. $$anonymous$$y matrix is then composed with the original bone pos and rot plus this offset, like this:
$$anonymous$$atrix4x4 mat;
mat = $$anonymous$$atrix4x4.TRS(initial_bone_mat.vec, initial_bone_mat.quat, Vector3.one);
$$anonymous$$atrix4x4 mat2;
mat2 = $$anonymous$$atrix4x4.TRS(boneChannel.position_key_list[i], boneChannel.rotation_key_list[i], Vector3.one);
mat = mat * mat2;
$$anonymous$$aybe the original position and rotation of bones are somehow doing something. I'm sorry but I'm very new to this thing, can't quite understand it all.
I've also slowed down animation and this bone rotates to the opposite direction it's supposed to. Need to turn from 359.90 to 360.1 but turns 359.90 to 0.1
...
($$anonymous$$e : Why does the ability to move an answer to comments requiere so much karma ...)
sorry, in my defense, "add new comment" should say, "answer to answer" :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613072340im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to modify animation curve in run time? 2 Answers
Scripted animation not working on windows 8 1 Answer
Export objects to a .3DS file at runtime 1 Answer
How to access AnimationCurve at runtime 4 Answers
Scripted animation not working 1 Answer