- Home /
See answer here: https://answers.unity.com/questions/275565/what-is-the-rotation-equivalent-of-inversetransfor.html
Quaternions local/world
Hi there,
I need to save a rotation relative to a specific transform in one place, and then convert that rotation relative to world space in another place. I'm not sure how to do that with quaternions.
If it was a position I would do this:
rightHandPostion = transform.InverseTransformPoint(rightHandJoint.position);
and then this:
transform.TransformPoint(rightHandPostion)
How would I handle this with a rotation?
Answer by robertbu · Jun 28, 2013 at 03:02 PM
Your words and your example don't match, so I'm not sure what you want to do. The example code transform from world to local and then back to world. If you are trying to get the relative rotation with respect to a parent, you can use Transform.localRotation. If you are talking about an arbitrary transform, you can use Quaternion.FromToRotation() of the Transform.forward of two transforms to get the relative rotation.
How would I apply the relative rotation that I get from Quaternion.FromToRotation() to get a global rotaion?
You are going to need to do a drawing for me or explain more fully before I can give you an accurate answer. Transform.rotation is the global rotation. FromToRotation() will give you a relative rotation between two directions, so in order to answer your question I would need to know how you are applying it to the new object. You may want:
var q = Quaternion.FromToRotation(transform1.forward, transform2.forward);
transform3.rotation = q * transform3.rotation;