[英]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.