This seems like it should be really simple, but I always seem to struggle with this conceptually.
Given a Transform “T” and a localEulerAngles, I want to know what the world eulerAngles of a child of “T” would be if the child had the given localEulerAngles.
So far, I’ve only been able to get this to work by creating a temp object, setting its parent and localEulerAngles, and then returning its world euler angles. Here’s that code:
public Vector3 GetWorldEulerAngles(Transform T, Vector3 localEulerAngles )
{
var tempGo = new GameObject("Temp");
tempGo.transform.SetParent(T);
tempGo.transform.localEulerAngles = localEulerAngles;
var retval = tempGo.transform.eulerAngles;
GameObject.Destroy(tempGo);
return retval;
}
This feels very ugly, but it does work. I’m trying to figure out how to get the same result without creating the temp object.
So, I want to answer the hypothetical question: “If I added a child to ‘T’ and gave it a particular localEulerAngles, what would its world eulerAngles be?”
I initially though I could use something like return T.rotation * localEulerAngles;
but that doesn’t seem to be right. Is there something easy I’m overlooking here? I don’t even see a way to convert a rotation from local to world and vice versa (only converting points or directions, not rotations).