【问题标题】:Rotating an object around an axis in unity统一围绕轴旋转对象
【发布时间】:2018-02-06 09:34:06
【问题描述】:

我正在尝试统一做一件简单的事情:围绕轴旋转对象。但是我遗漏了一些东西,我的对象只是向下移动,而不是围绕轴旋转。

这是我的更新功能:

this.transform.RotateAround(new Vector3(1,0,5), new Vector3(0,1,0), 10 * Time.deltaTime);

其中 (1,0,5) 是旋转中心。我的对象在位置 (0,0,0)。 对象只是向下移动,而不是旋转。 知道为什么会这样吗?

【问题讨论】:

  • 可以添加 gif 或链接到正在发生的事情的视频。
  • 这行代码看起来是正确的。你确定你没有移动你的对象的另一行或另一个脚本。评论此行时它会停止移动吗?
  • 其他可能的问题是,如果变换有一个位置不同的子对象,并且 OP 实际上想要旋转该对象,而不是其父对象。
  • 我认为 RotateAround 适用于世界坐标,所以如果你的游戏对象远离那个 (1,0,5) 它会在一个大圆圈上移动

标签: c# unity3d


【解决方案1】:

我认为它可以解决您的问题。这是您需要的脚本:

using UnityEngine;

public class RotateObj : MonoBehaviour
{
    private void Update()
    {
        // rotate to its own axis
        transform.Rotate(new Vector3(Random.value, Random.value, Random.value)); 

        // rotate about axis passing through the point in world coordinates
        transform.RotateAround(Vector3.zero, Vector3.up, 1.0f); 
    }
}

这是你的统一配置:

它围绕自己(随机)和Vector3.zero坐标旋转

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-10
    • 2015-01-06
    • 2015-07-14
    • 2015-07-23
    • 1970-01-01
    • 2014-11-15
    相关资源
    最近更新 更多