C# Unity3D:将子对象放入其中';平移和旋转后的原始位置 这是立方体及其子对象圆锥体的原始位置
C# Unity3D:将子对象放入其中';平移和旋转后的原始位置 这是立方体及其子对象圆锥体的原始位置,c#,unity3d,rotation,parent-child,translation,C#,Unity3d,Rotation,Parent Child,Translation,在这里,我已经翻译了2个单位的圆锥体 现在,我已经将父立方体旋转了25度,与Y轴垂直 如果我们再次将圆锥体平移2个单位,它将不在原始位置 在将圆锥体平移回其原始位置时,我需要对其应用什么公式?如果使用transform.Translate()方法统一移动对象,并且希望与其父对象保持相对,则一种方法是将父对象的变换传递给中的空间参数 像这样: var parent = transform.parent; transform.Translate(0, 0, 2, parent); //
在将圆锥体平移回其原始位置时,我需要对其应用什么公式?如果使用transform.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项目中重新创建了您的问题,并使用上面的方法修复了它。谢谢!成功了。但是,是否可以相对于父级使用Vector3.Lerp()?