【问题标题】:how to make a gameObject rotate around another gameObject in Unity in the rotating plane如何使游戏对象在旋转平面中围绕 Unity 中的另一个游戏对象旋转
【发布时间】:2016-08-02 15:40:36
【问题描述】:

我有两个游戏对象sphereOnesphereTwo 作为空游戏对象both 的子对象。

我已将此 C# 代码附加到 sphereTwo

private void Update() =>
    transform.RotateAround(sphereOne.transform.position, 
        new Vector3(0, 1, 0), 100 * Time.deltaTime);

这让sphereTwo 围绕sphereOne 旋转。

当我旋转父游戏对象both 时,它只在该特定平面上旋转。

如何动态更新旋转球体的变换位置,使其与父对象的旋转位于同一平面上?

【问题讨论】:

  • 在正确的平面上将它的位置向量设置为其父级的位置向量?
  • 这里的秘密是你有一个空的游戏对象(通常称为“标记”)来“持有”这些东西。

标签: c# unity3d rotation


【解决方案1】:

Transform.RotateAround() 中的第二个参数是确定sphereTwo 围绕sphereOne 旋转的平面的方向的轴。现在,您已将此设置为静态值 new Vector3(0, 1, 0),基本上是世界的向上向量。

要使轴基于sphereOne 的方向,请改用其Transform.up 向量 - 这将根据sphereOne 变换的世界空间旋转而改变:

private void Update() 
{
    transform.RotateAround(sphereOne.transform.position, sphereOne.transform.up, 100*Time.deltaTime);
}

(您也可以使用both.transform.up,视情况而定。)

希望这会有所帮助!如果您有任何问题,请告诉我。

【讨论】:

  • 没错,但是 OP 需要学习如何堆叠转换以实现这样的东西!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-23
  • 1970-01-01
相关资源
最近更新 更多