语言English
  • C#

Transform.InverseTransformDirection

切换到手册

声明

public Vector3 InverseTransformDirection(Vector3 direction);

描述

direction从世界空间转换到局部空间。与Transform.TransformDirection相反。

此操作不受变换的缩放或位置的影响。转换后的向量与原始向量具有相同的长度。

如果您需要从局部空间转换到世界空间的反向操作,可以使用Transform.TransformDirection

如果向量表示空间中的位置而不是方向,则应使用Transform.InverseTransformPoint

如果您需要一次转换多个方向,请考虑使用Transform.InverseTransformDirections,因为它比重复调用此函数快得多。

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // transform the world forward into local space: Vector3 relative; relative = transform.InverseTransformDirection(Vector3.forward); Debug.Log(relative); } }

声明

public Vector3 InverseTransformDirection(float x, float y, float z);

描述

将方向xyz从世界空间转换到局部空间。与Transform.TransformDirection相反。

此操作不受变换的缩放或位置的影响。转换后的向量与原始向量具有相同的长度。

如果您需要从局部空间转换到世界空间的反向操作,可以使用Transform.TransformDirection

如果向量表示空间中的位置而不是方向,则应使用Transform.InverseTransformPoint

如果您需要一次转换多个方向,请考虑使用Transform.InverseTransformDirections,因为它比重复调用此函数快得多。

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // transform the world forward into local space: Vector3 relative; relative = transform.InverseTransformDirection(Vector3.forward); Debug.Log(relative); } }

Did you find this page useful? Please give it a rating: