- Home /
Transform.TransformDirection with a custom EulerAngle (Vector3)
Transform.TransformDirection use the transform's rotation to calculate the world direction. I what to use any EulerAngle (or Vector3) and get the exact same result.
What should I do?
Answer by JamesFowardSnobal · Jun 15, 2017 at 06:32 AM
You'll need to use Quaternions to do this. You can add two rotations together by multiplying them in Quaternion form. So transform your local EulerAngle into a transform and then multiply it an objects global rotation to get the angle in global coords, then transform back to Euler angles.
Vector3 localEulerAngle;
Vector3 worldAngle = (transform.rotation * Quaternion.Euler(localEulerAngle)).eulerAngles;
Answer by aldonaletto · Jun 15, 2017 at 04:13 AM
TransformDirection transforms a direction vector from local space to the world space. If you want to rotate any vector according to some given Euler angles, you can use Quaternion.Euler like this:
Vector3 newVector = Quaternion.Euler(0,30,0) * someVector;
This code rotates the vector someVector 30 degrees about the Y axis and store the result in newVector. Notice that you must follow the order quaternion * vector.
Your awnsers was right but I choosed to accept JamesFowardSnobal's one because the code was more complete. Thanks anyway.