- Home /
Smooth bone rotation
I have an animation and I modified some rotations of some bones in the animation at a certain frame. What I want to do is how to make the animation in the next couple of frames interpolate smoothly so that the changes I made looks smooth? Like for example, if I have an animation of a game object, and in frame number 100 it rotated 90 degree in the x-direction. So now frame 100 has a modified rotation angle of the object, but frame 101 has the original animation. I want to smooth the rotation so that the transition of the object from the modified frame back to the original animation looks smooth.
Answer by PlatformSix · Jun 11, 2015 at 09:07 AM
Maybe store your manually set new position, then lerp between the animation and the manual position. Something like...
void LateUpdate () {
float transitionStartTime = 2.0f;
float transitionDuration = 4.0f;
Quaternion manualRotation = Quaternion.Euler (90, 0, 0);
Quaternion animationRotation = jointToRotate.transform.localRotation;
float lerp = 1 - Mathf.Clamp01((Time.time - transitionStartTime) / transitionDuration);
jointToRotate.transform.localRotation = Quaternion.Lerp (animationRotation, manualRotation, lerp);
}
Answer by zach-r-d · Jun 11, 2015 at 02:51 AM
Assuming the animation has keyframes at later frames (say you wanted it to be back to the original animation by frame 106), you might be able to just delete the intermediate keyframes (e.g. 101-105) in the Animation window. You may need to edit the tangents of the keyframes at the ends to get the curve the way you want for the transition.
But I want to do this through scripting so that I do it on the runtime.
Ah, okay, you didn't mention that. In that case, you should probably have two separate animations: the normal one, and a copy of the normal one that has the arms rotated upwards. Then you can use a blend tree in the character's animation controller to blend between them.
Your answer
Follow this Question
Related Questions
Attack Animation problem 1 Answer
Can I make animations snap to a frame? 1 Answer
All AI animations stop on first frame 0 Answers
Select frame for Animation 1 Answer
Switch between animations but keeping frame number? 0 Answers