[英]Unity3D: Bring child objects in it's original position after it is translated and rotated
如果您在 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.