【发布时间】:2020-08-18 00:23:31
【问题描述】:
- 这是立方体及其子对象圆锥的原始位置。
在将锥体平移回原来的位置时,我需要对它应用什么公式?
【问题讨论】:
标签: c# unity3d rotation parent-child translation
在将锥体平移回原来的位置时,我需要对它应用什么公式?
【问题讨论】:
标签: c# unity3d rotation parent-child translation
如果您在 Unity 中使用 transform.Translate() 方法移动对象并且希望保持相对于它的父对象,那么执行此操作的一种方法是将父对象的变换传递给空间参数Translate.
像这样:
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 项目中重新创建了您的问题,并使用上述方法修复了它。
【讨论】: