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
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.
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.
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).