How to fix the rotation of my IK foot?
I was following a youtube tutorial on how to set up an IK system for the feet of my character and I managed to achieve the "desired" result, that is, the IK system works, however, I'm still in the process of assimilate and understand each line completely and I noticed something with the rotation of my feet that I don't know how to solve, I'll attach a picture that shows it more clearly:
So what I want to learn is how to make the IK system "respect" the original rotation of the animation and then rotate accordingly. Any pointers are appreciated :)
Answer by REF · Jan 19, 2019 at 06:32 PM
Yay! For future generations that could come across the same problem as me, look no further because I bring you the solution!
Use these lines to fix your rotation problem:
Vector3 rotAxis = Vector3.Cross(Vector3.up, hit.normal);
float angle = Vector3.Angle(Vector3.up, hit.normal);
Quaternion rot = Quaternion.AngleAxis(angle * weight, rotAxis);
feetIKRotation = rot;
Then apply the rotation!:
animator.SetIKRotation(foot, feetIKRotation * animator.GetIKRotation(foot));
Now your feet's rotation will be the same as in your animation but with all the benefits of IK!
The last line was just what I was needing. Thank you so much! For others, just remove the transform.rotation and replace it with animator.GetIKRotation(foot). So the feet are going to be rotate with the animation rotation and not from your transform. =)
Last line fixed my feet not adjusting with the right animation! thanks!!
Answer by Nielsvdmarel · Feb 19, 2021 at 12:07 AM
Thanks for the fix! indeed the last line you posted was just what I needed!
Your answer
Follow this Question
Related Questions
How can I edit animations of a character downloaded from Asset Store? 1 Answer
Rotating 2D Sprite 0 Answers
Pick up and carry objects in third person. 2 Answers
Move Character animator 0 Answers
I have my animations created. Now what? 0 Answers