Transforms position
from world space to local space. The opposite of Transform.TransformPoint.
Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.
#pragma strict // Calculate the transform's position relative to the camera. public var cam; public var cameraRelative; function Start() { cam = Camera.main.transform; var 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"); }
// 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"); } }
Transforms the position x
, y
, z
from world space to local space. The opposite of Transform.TransformPoint.
Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with directions.
#pragma strict // Calculate the world origin relative to this transform. function Start() { var 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"); }
// 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"); } }