- Home /
Transform a vector from local space to world space by rotation only.
I have a vector local to an object, and I want to undo the rotation from it's parent to get the vector's value in worldspace. I dont want to transform it by position or scale.
For example:
transform.Translate(Random.insideUnitSphere * 1000); // should be ignored transform.localScale = Vector3(10,20,30); // should be ignored
transform.Rotate(0, 0, 90); var myVector = Vector3(10, 0, 0); var transformedVector = myVector.SomethingMagicHere(); // What goes here?
Debug.Log(transformedVector); //desired return value: Vector3(0, 10, 0)
I'm trying to figure out if I somehow rotate myVector
by transform.forward
, or use a Quaternion
method os some sort? I'm sure this is simple, I'm just a bit confused.
Answer by Molix · Apr 23, 2010 at 12:44 AM
I think you're looking for transform.TransformDirection, e.g.
var localOffset = Vector3( 10, 0, 0 );
var worldPosition = transform.TransformDirection( localOffset );
I knew there was a built in method there somewhere, thanks!
Your answer
Follow this Question
Related Questions
Lookat function moves object backwards 0 Answers
Relative Rotation 1 Answer
How do I align my player transform to waypoints and without restricting Z Axis rotation? 2 Answers
Keep camera at certain distance from character when rotating 3 Answers
How do you make a gameobject rotate slowly to the direction of the mouseclick 0 Answers