Comments and answers for "Get local euler angles by Quaternion"
http://answers.unity.com/questions/1417640/get-local-euler-angles-by-quaternion.html
The latest comments and answers for the question "Get local euler angles by Quaternion"Comment by lPVDl on lPVDl's answer
http://answers.unity.com/comments/1420976/view.html
It's working, thanks!Sun, 15 Oct 2017 13:23:00 GMTlPVDlAnswer by Bunny83
http://answers.unity.com/answers/1420860/view.html
You seem to abuse a child object as temporary conversion object while you actually want to access the rotation of the parent object. The local eulerangles define the rotation of the transform in the parents coordinate space. So if your targetRotation quaternion is an absolute / worldspace rotation all you need is the inverse of the parents transform
So to replace your current code you can just do:
static Vector3 GetLocalEulerAtRotation(this Transform transform, Quaternion targetRotation)
{
var q = Quaternion.Inverse(transform.parent.rotation) * targetRotation ;
return q.eulerAngles;
}
It would make more sense to use the transform as local space instead of the parent of the objectSun, 15 Oct 2017 02:31:22 GMTBunny83