首页 文章

围绕轴旋转对象

提问于
浏览
0

我试图在统一中做一个简单的事情:围绕轴旋转一个物体 . 但是我错过了一些东西,我的物体只是向下移动,而不是围绕轴旋转 .

这是我的更新功能:

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

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

1 回答

  • 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); 
        }
    }
    

    这是你的统一配置:

    enter image description here

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

    enter image description here

相关问题