InverseTransformPoint
变换位置从世界坐标到局部坐标。和Transform.TransformPoint相反。
InverseTransformDirection
变换的方向从世界坐标转换到局部坐标。和Transform.TransformDirection相反。
例如物体a属于x的子物体,
现在将a移动物体b的位置时(a还是属于x的子物体) 打印出来他的自身坐标,
x.InverseTransformPoint(b.transform.position));
using
System.Collections;
using
System.Collections.Generic;
using
UnityEngine;
public
class
Test
:
MonoBehaviour
{
public
Transform
A;
//
public
Transform
B;
//A的子物体
public
Transform
C;
//B的子物体
public
Transform
D;
//C的子物体
public
Transform
E;
//外界物体
public
Transform
F;
//E的子物体
public
Transform
G;
//外界物体
private
void
Start
()
{
//现在要求,D在A的同一位置(A当做世界)
Vector3
v4 = A.transform.TransformPoint(D.localPosition);
//局部--》世界
// D.localPosition= D.InverseTransformPoint(v4);// D.position = A.position;
//要求D在E的位置
// D.localPosition = C.transform.InverseTransformPoint(E.position);//世界--》局部
//要求F在D的位置
// F.localPosition = D.transform.InverseTransformPoint(D.position);
}
}