Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


InverseTransformPoint

Transforms the position x, y, z from world space to local space.
Read time 2 minutesLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

InverseTransformPoint(float, float, float)

Transforms the position
x
,
y
,
z
from world space to local space.
public Vector3 InverseTransformPoint(float x, float y, float z)

Parameters

Returns

Type

Description

Vector3

Remarks

This function is essentially the opposite of TransformHandle.TransformPoint which is used to convert from local to world space.
Note that the returned position is affected by scale. Use TransformHandle.InverseTransformDirection if you are dealing with direction vectors rather than positions.
If you need to transform many points at once consider using TransformHandle.InverseTransformPoints instead as it is much faster than repeatedly calling this function.
// Calculate the world origin relative to this transform.using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Start() { Vector3 relativePoint = transformHandle.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"); }}

InverseTransformPoint(Vector3)

Transforms
position
from world space to local space.
public Vector3 InverseTransformPoint(Vector3 point)

Parameters

point

Returns

Type

Description

Vector3

Remarks

This function is essentially the opposite of TransformHandle.TransformPoint which is used to convert from local to world space.
Note that the returned position is affected by scale. Use TransformHandle.InverseTransformDirection if you are dealing with direction vectors rather than positions.
If you need to transform many points at once consider using TransformHandle.InverseTransformPoints instead as it is much faster than repeatedly calling this function.
// Calculate the transform's position relative to the camera.using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public TransformHandle cam; public Vector3 cameraRelative; void Start() { cam = Camera.main.transformHandle; Vector3 cameraRelative = cam.InverseTransformPoint(transformHandle.position); if (cameraRelative.z > 0) print("The object is in front of the camera"); else print("The object is behind the camera"); }}