# missunderstatnding of transform.InverseTransformDirection(Vector3.forward)

Hello there! Can somebody help me to understand how it works? If i rotate object 90 degrees around it's Y-axis and draw a ray

``````Gizmos.DrawRay(transform.position, transform.InverseTransformDirection(Vector3.forward) * 10f);
``````

Why the Ray point in the direction of Vector3.left in world space instead of Vector3.right?

Toggle Center / Pivot and Global / Local in the scene window, either with the buttons or with Z and X

Thank you for reply but i need a physical meaning. Why it works like that, if i rotate object clockwise the ray rotate conterclockwise?

I think it is because you are inversing a world vector (Vector3.forward).

What happens if you feed in Transform.forward? It should always return (vanishingly near) Vector3.forward.

``````Gizmos.DrawRay(transform.position, transform.forward * 10f);
``````

In this case ray point in the same direction as local forward axis(z axis).
I thought that transform.forward and transform.InverseTransformDirection(Vector3.forward) should return the same result

This is not correct. transform.forward is dependent on the orientation of the transform, Vector3.forward doesnâ€™t ever change.

yes, Vector3.forward doesnâ€™t change but method transform.InverseTransformDirection(Vector3.forward) return result which depends on object orientation. And iâ€™m trying to understand why that result as it is.

I'm still not sure what you're expecting to happen.

Does this look correct or wrong to you?

1 Like

`transform.forward` is the same as

`transform.rotation * Vector3.forward`

1 Like

For me itâ€™s look wrong. I donâ€™t understand why the ray is
also rotates. Perhaps Iâ€™m misunderstanding how an object in local space should work.

VectorInWorldSpace = TransformDirection( VectorInLocalSpace )

• `transform.forward == transform.TransformDirection(Vector3.forward)`
• `transform.forward == transform.rotation * Vector3.forward`

VectorInLocalSpace = InverseTransformDirection( VectorInWorldSpace )

• `Vector3.forward == transform.InverseTransformDirection(transform.forward)`
• `Vector3.forward == AMysticalFunctionTakingTheInverseOf(transform.rotation * Vector3.forward)`

It would usually be confusing and meaningless to do InverseTransformDirection of a world vector.

Post #18 in this thread is my earlier writeup.

2 Likes

You are converting a fixed world direction that doesnâ€™t move to a local one that does move.

You are converting world direction to local direction, and then you draw using the converted local direction as a world direction.

Assume we are talking about euler y angles. Vector3.forward is 0. Letâ€™s assume the cube is at +20 degrees in y. 0 converted to local space is 0 - 20 = -20, then you draw a line towards -20.

2 Likes

Thank you! Great explanation by link

Thank you. If i understand right. When i rotate cube in Y at +20 degrees, the Vector3.forward becomes -20 and the angle between local cube facing and local vector3.forward will be 40 degrees?

No. `transform.forward` returns the same as `transform.TransformDirection(Vector3.forward)` which both give you a world space vector. I donâ€™t know where you got the idea of using the inverse method from. You simply used the wrong method. So whenever youâ€™re dealing with vectors / points you should be aware of the coordinate system they belong to.

I think youâ€™re loosing yourself in certain details without understanding the bigger picture. This all just boils down to understand what a coordinate system / coordinate space is, how vectors and transformations work. On the bottom line this is just linear algebra. If you havenâ€™t watched it yet (or you watched it years ago) I would highly recommend to watch the essence of linear algebra series by 3b1b (again).

1 Like

Thank you for suggestions