Unity - Scripting API: Transform.InverseTransformPoint
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Transforms position from world space to local space.
// 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"); } }
Declaration
public Vector3 InverseTransformPoint(float x, float y, float z);
Description
Transforms the position x, y, z from world space to local space.
// 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 this object"); } }