I know TransformDirection can convert local to world coordinates. Can can tell me how the math behind the process works?
The transform of a gameobject has a matrix storing information like position, rotation and scale. TransformDirection multiplies the input vector with the transform’s matrix and returns the result. InverseTransformDirection multiplies the input vector with the transpose of the transform’s matrix. In 3d it is a 4 by 4 matrix, in 2d 2 by 2 matrices are used.
You have to decompose the rotation component of the matrix.
There is a Matrix4x4.rotation property. It returns a Quaternion. Simply rotate your direction vector with that Quaternion.