Version: 2019.1

Transform.InverseTransformPoint

Switch to Manual
public Vector3 InverseTransformPoint (Vector3 position);

Description

Преобразует position (позицию) из мировой в локальную систему координат. Противоположно Transform.TransformPoint.

This function is essentially the opposite of Transform.TransformPoint, which is used to convert from local to world space.

Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with direction vectors rather than positions.

// Calculate the transform's position relative to the camera.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform cam; public Vector3 cameraRelative;

void Start() { cam = Camera.main.transform; Vector3 cameraRelative = cam.InverseTransformPoint(transform.position);

if (cameraRelative.z > 0) print("The object is in front of the camera"); else print("The object is behind the camera"); } }

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

Description

Преобразует позицию по x, y, z из глобальной в локальную систему координат. Противоположно Transform.TransformPoint.

Обратите внимание на то, что возвращаемое значение позиции зависит от масштабирования (scale). Используйте Transform.InverseTransformDirection если вы работаете с направлением.

// Calculate the world origin relative to this transform.
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Vector3 relativePoint = transform.InverseTransformPoint(0, 0, 0);

if (relativePoint.z > 0) print("The world origin is in front of this object"); else print("The world origin is behind of this object"); } }