繁体   English   中英

Unity3D:平移和旋转后将子对象带入其原始 position

[英]Unity3D: Bring child objects in it's original position after it is translated and rotated

  1. 这是立方体的原始 position 及其子圆锥体 object。

在此处输入图像描述

  1. 在这里,我已经翻译了 2 个单位的圆锥体在此处输入图像描述

  2. 现在我已经将父立方体相对于 Y 轴旋转了 25 度在此处输入图像描述

  3. 如果我们再次将锥体平移 2 个单位,它就不是原来的 position 在此处输入图像描述

在将其转换回原来的 position 时,我需要将什么公式应用于圆锥体?

如果您在 Unity 中使用 transform.Translate() 方法移动 object 并且您希望保持相对于它的父级,那么一种方法是为 Translate 中的 Space 参数传入父级的转换

像这样:

var parent = transform.parent;

transform.Translate(0, 0, 2, parent); // 2. Over here, I have translated the cone for 2 units
parent.Rotate(0, 25, 0); // 3. Now I have rotated the parent cube around 25 degrees wrt to the Y-axis

transform.Translate(0, 0, -2, parent); // 4. If we translate the cone 2 units back again, it's now in the original position

我在一个新的 Unity 项目中重新创建了您的问题,并使用上面的方法修复了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM