TransformDirection

I think I’m missing something here because I’m really not getting the expected behavior from the TransformDirection method.

Here is the code:

public Vector3 testVector
void Update()
{
    Vector3 worldSpace = bone.transform.TransformDirection(testVector);
    bone.transform.eulerAngles = worldSpace;
}

From the docs I would expect that the TransformDirection method would return the world space of the testVector. Therefore applying the resulting vector every frame would always yield the same result if the testVector remained unchanged. However I’m seeing many different worldSpace results from the same testVector. Is this the correct behavior or has something gone wrong?

1620296--99089--$results.jpg

Thanks!

TransformDirection does not give you Euler angles. It gives you a “forward vector”. (It also takes a forward vector as input) In your example, if testVector was (1, 0, 0) (pointing right), the result of transform.TransformDirection would always give you a vector that points in the direction of the transform’s right side.

If you want to transform a rotation, it’d look more like this:

Vector3 inputEulerAngles; //this will be in "local space" to the transform in question
void Update() {
Quaternion inputRotation = Quaternion.EulerAngles(inputEulerAngles);
Quaternion finalRotation = transform.rotation * inputRotation;
}