本文共 591 字,大约阅读时间需要 1 分钟。
计算Unity场景中物体B在物体A坐标系下的坐标,且两物体没有父子关系
计算一个物体A的position相对于另一个物体B(origin)的坐标
private Vector3 GetRelativePosition(Transform origin, Vector3 position){ Vector3 distance = position - origin.position; Vector3 relativePosition = Vector3.zero; relativePosition.x = Vector3.Dot(distance, origin.right.normalized); relativePosition.y = Vector3.Dot(distance, origin.up.normalized); relativePosition.z = Vector3.Dot(distance, origin.forward.normalized); return relativePosition;}
计算物体A在物体B下的坐标,即将物体B的坐标origin视为坐标原点,物体A的坐标即为(B-A)*B的归一化方向。
转载地址:http://wloen.baihongyu.com/