Unity之计算子节点世界坐标

        //计算子物体的世界坐标
        //父结点
        Transform parent = gameobj1.transform.parent;
        //结点偏差
        Vector3 offset = new Vector3(gameobj1.transform.localPosition.x * parent.transform.localScale.x,
                                     gameobj1.transform.localPosition.y * parent.transform.localScale.y,
                                     gameobj1.transform.localPosition.z * parent.transform.localScale.z);
        //子节点世界坐标
        Vector3 worldPos = parent.position + parent.rotation * offset;
        Debug.LogError("local pos " + gameobj1.transform.localPosition + "  worldPos " + gameobj1.transform.position + "  cal WorldPos " + worldPos);


 
 

你可能感兴趣的:(游戏开发语言之Unity3D)