Transform.InverseTransformPoint
获得 position 的本地坐标, position 是一个世界坐标点
最后获得 position 在本地坐标中的相对坐标
举例:如 transform.positon = (1,0,0)
则下面是获取世界坐标 (2,0,0) 相对于本地位置 (1,0,0) 的坐标即 (1,0,0)
Debug.Log(transform.InverseTransformPoint(2, 0, 0));
Transform.TransformPoint
获得 position 的世界坐标
position 是基于当前物体本地坐标上的相对坐标(位移)
举例:如 transform.positon = (1,0,0) 则下面的结果应该为 (3,0,0)
Debug.Log(transform.TransformPoint(2, 0, 0));
Transform.InverseTransformDirection
获取 direction 在本地坐标中的方向向量,direction 本来是世界坐标系中的方向向量
只会受物体的 rotation 所影响
如果物体在 x 轴旋转 90 度后,则世界坐标的 up (0,1,0) 为本地的 -forward (0,0,-1)
Debug.Log(transform.InverseTransformDirection(Vector3.up));
Transform.TransformDirection
获取 direction 的世界坐标
如果物体在 x 轴旋转 90 度后,则它的 up 为世界坐标中的 forward
Debug.Log(transform.TransformDirection(Vector3.up));
获得 position 的本地坐标, position 是一个世界坐标点
最后获得 position 在本地坐标中的相对坐标
举例:如 transform.positon = (1,0,0)
则下面是获取世界坐标 (2,0,0) 相对于本地位置 (1,0,0) 的坐标即 (1,0,0)
Debug.Log(transform.InverseTransformPoint(2, 0, 0));
Transform.TransformPoint
获得 position 的世界坐标
position 是基于当前物体本地坐标上的相对坐标(位移)
举例:如 transform.positon = (1,0,0) 则下面的结果应该为 (3,0,0)
Debug.Log(transform.TransformPoint(2, 0, 0));
Transform.InverseTransformDirection
获取 direction 在本地坐标中的方向向量,direction 本来是世界坐标系中的方向向量
只会受物体的 rotation 所影响
如果物体在 x 轴旋转 90 度后,则世界坐标的 up (0,1,0) 为本地的 -forward (0,0,-1)
Debug.Log(transform.InverseTransformDirection(Vector3.up));
Transform.TransformDirection
获取 direction 的世界坐标
如果物体在 x 轴旋转 90 度后,则它的 up 为世界坐标中的 forward
Debug.Log(transform.TransformDirection(Vector3.up));