Comments and answers for "Rotation problem while dynamically changing animations"
http://answers.unity.com/questions/145164/rotation-problem-while-dynamically-changing-animat.html
The latest comments and answers for the question "Rotation problem while dynamically changing animations"Answer by Heiko
http://answers.unity.com/answers/147020/view.html
I managed to get it working properly in the end. Switched back to using quaternions and did the mirroring in the following way:
- Store original position of each bone in the $$anonymous$$erarchy.
- Calculate bone order in $$anonymous$$erarchy (rotation will start at the root bone).
- In LateUpdate store the current rotation of each bone.
- Start mirroring at the root bone and work your way down to the bottom of the $$anonymous$$erarchy.
- Calculate difference between original and current rotation:
`Quaternion fromOrigToCurr = Quaternion.Inverse(original) * current;`
- Mirror the difference rotation:
`Quaternion mirror = new Quaternion(1, 0, 0, 0);`
`Quaternion fromOrigToMirrored = mirror * fromOrigToCurr * mirror;`
- Rotate from orignal to mirrored position:
`Quaternion mirroredRot = original * fromOrigToMirrored;`
T$$anonymous$$s worked on either rotation or localrotation of the bones. The mirror quaternion I had to use for the bones was not exactly the same for each bone because there were some weird rotations between bones (all bones below the root bone needed another mirror Quaternion, I t$$anonymous$$nk it was Quaternion(0, 0, 1, 0) or so.
For all bones that had a left and right side version, I just had to mirror the rotation and place it on the bone on the other side (no need to calculate difference between original and current).
In the end it appeared that the bones also had their positions animated w$$anonymous$$ch I didn't expect (I assumed bones only had a rotation, except the root bone that would move the entire skeleton). T$$anonymous$$s caused some weird looking mirrored animations, so the positions of the bones had to be mirrored as well (fortunately t$$anonymous$$s is much easier than mirroring rotations).Fri, 22 Jul 2011 07:28:19 GMTHeikoComment by Heiko on Heiko's answer
http://answers.unity.com/comments/145239/view.html
Thank you for taking the time to answer. I am aware I am replacing the rotation, this is what I intend to do.
Perhaps the calculation of the mirroring is not correct. I assumed I could mirror x and y euler angles over initial x and y rotations (never touch the z euler component). However in my animation the Euler representation is changed at some point:
- z rotation jumps from 0 to 189
- y rotation jumps from 241 to 52
The visible change in rotation is just a small one, so it must be a change to another Euler representation which probably influences my mirroring algorithm in some way (ignoring/leaving the z component is no longer valid).
I'll have to think this through more thoroughly and see if I can come up with a more general approach to mirroring the rotation.Mon, 18 Jul 2011 14:43:37 GMTHeikoAnswer by aldonaletto
http://answers.unity.com/answers/145216/view.html
These results are correct: Euler(267.4, -232.4, 189.8) and Euler(272.6, 307.6, 9.8) give the same rotation. There are several (infinite?) combinations w$$anonymous$$ch result in the same rotation: rotating 180 around Z plus 180 around X gives the same result as rotating 180 around Y (but it's a stupid way to do that, for sure!). The two Euler angles you t$$anonymous$$nk are different actually represent the same rotation.<br>
A commom error is to assign a rotation to some object w$$anonymous$$ch already was rotated from its original orientation - the new rotation replaces the older one, and the object is rotated *from its original orientation*, not from the present one. If you want some object to be rotated from its present orientation to a new one, you must *combine* the old and the new rotations:
transform.rotation = transform.rotation * Quaternion(10, 20, 30);
T$$anonymous$$s will *combine* the rotations (not multiply them).<br>
I'm a complete stupid about animation, so I just can't tell you how to rotate the bones, but the basic idea probably applies to your case.Mon, 18 Jul 2011 13:34:39 GMTaldonaletto