Transform.InverseTransformPointfunction InverseTransformPoint (position : Vector3) : Vector3DescriptionTransforms 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.
JavaScripts
// Calculate the transform's position relative to the camera.
var 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"); using UnityEngine;
using System.Collections; public class example : MonoBehaviour { public Transform cam = Camera.main.transform; public Vector3 cameraRelative = cam.InverseTransformPoint(transform.position); void Awake() { if (cameraRelative.z > 0) print("The object is in front of the camera"); else print("The object is behind the camera"); } } import UnityEngine
import System.Collections class example(MonoBehaviour): public cam as Transform = Camera.main.transform public cameraRelative as Vector3 = cam.InverseTransformPoint(transform.position) def Awake(): if cameraRelative.z > 0: print('The object is in front of the camera') else: print('The object is behind the camera') function InverseTransformPoint (x : float, y : float, z : float) : Vector3DescriptionTransforms 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.
JavaScripts
// Calculate the world origin relative to this transform.
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"); using UnityEngine;
using System.Collections; public class example : MonoBehaviour { void Awake() { 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"); } } import UnityEngine
import System.Collections class example(MonoBehaviour): def Awake(): 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') |
