- Home /
Modifying animations with IK
So I have an animation for holding a gun. I need to rotate the shoulders and the spine for the character to aim up/down. From what I understood, Unity's default IK doesn't support modifying animations, but posing instead, which is the opposite of what i want. How can I modify certain properties of animations through IK/scripting? Apologies for my poor English and explaining and thanks in advance.
Answer by Cherno · May 13, 2015 at 05:54 PM
I answered a similar question a few weeks agho, but I can't find the thread. Anyway, you need to apply and changes to a bone's transform in LateUpdate() to ensure it gets applied after any manipulations from animations took place.
As for IK, there are IK solutions on the Asset store, I use SimpleIK, it's only $2.
I tried using this script without any effect:
void LateUpdate ()
{
float armRotation = Input.GetAxisRaw("RightVertical") * 2f;
if(ikActive)
{
if(rightArmJoint != null)
{
rightArmJoint.transform.Rotate(new Vector3(armRotation, 0, 0));
}
if(leftArmJoint != null)
{
leftArmJoint.transform.Rotate(new Vector3(armRotation, 0, 0));
}
}
}
I think the problem with your script is that it works... But now as you intend. transform.Rotate gets called, but in the next frame, i.e. immediately after, the animation kicks in again, and then transform.Rotate again, and so on, so there is no effect. Ins$$anonymous$$d, change the rotation of a bone to a set value ins$$anonymous$$d of rotating towards it gradually.
Hey, it worked! Thanks. Now I just have to fix the bugs. :P
Your answer
Follow this Question
Related Questions
Using IK the head is not returning smooth to his natural look position how can I fix it ? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Trouble with animation with Forge Networking Remastered in MP 0 Answers
What is the proper way to wait for an Animator Controller to update? 1 Answer