简体   繁体   English

围绕轴统一旋转对象

[英]Rotating an object around an axis in unity

I'm trying to do a simple thing in unity: rotate an object around an axis. 我试图统一做一个简单的事情:绕轴旋转对象。 But I'm missing something, my object just goes in the downward direction, instead of rotating around the axis. 但是我缺少了一些东西,我的对象只是向下移动,而不是绕轴旋转。

This is my update function: 这是我的更新功能:

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

where (1,0,5) is the center of rotation. 其中(1,0,5)是旋转中心。 My object is at position (0,0,0). 我的对象在位置(0,0,0)。 The object just moves down, instead of rotating. 对象只是向下移动,而不是旋转。 Any idea why this is happening? 知道为什么会这样吗?

I think it can solve your problem. 我认为它可以解决您的问题。 This is the script you need: 这是您需要的脚本:

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

and this is your unity configuration: 这是您的统一配置:

在此处输入图片说明

And it rotates around itself (randomly) and Vector3.zero coordinates 并且它围绕自身(随机)和Vector3.zero坐标旋转

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM