更改GameObject轴心点 [英] Change GameObject pivot point
问题描述
统一对象不在中心旋转.直到一个小时都没事,我不相信我更改了代码或任何东西.我也尝试过弄乱左上方的枢轴/中心按钮,但没有任何帮助.游戏对象不在中间旋转.
Unity object not rotating in center. It was fine until an hour, I don't believe I changed the code or anything. I have also tried messing with the pivot/centre buttons on the top left but nothing is helping. The game Object is not rotating in the middle.
旋转代码:
using UnityEngine;
public class Rotator : MonoBehaviour
{
public float speed = 100f;
// Update is called once per frame
void Update()
{
transform.Rotate(0f, 0f, speed * Time.deltaTime);
}
}
推荐答案
Rotate
函数Space.Self
的默认空间.您应该为其Space.World
提供第三个参数,以使其在世界空间中旋转.
The default space of the Rotate
function Space.Self
. You should provide Space.World
to its third parameter to make it rotate in world space.
transform.Rotate(0f, 0f, speed * Time.deltaTime, Space.World);
如果这不能解决问题,则必须在任何3D应用程序(例如Maya)中打开模型,并重置/居中枢轴点,然后将其重新导入到Unity中.
If this does not solve your problem, you have to open your model up in any 3D application such as Maya and reset/center the pivot point then re-import it into Unity.
您也可以将另一个GameObject用作要旋转的GameObject的父对象,以解决此关键问题.
You can also use another GameObject as parent of this GameObject you want to rotate to solve this pivot issues.
1 .创建一个新的GameObject
1.Create a new GameObject
2 .将其移动到要旋转的对象的中心位置.
2.Move it to the center position of the object you are rotating.
3 .确定该位置后,将要旋转的对象拖动到在#1 中创建的GameObject下.您正在旋转的GameObject现在应该是在#1 中创建的GameObject的子代.
3.Once you are fine with that location, drag that object you are rotating under the GameObject created in #1. The GameObject you are rotating should now be a child of that GameObject created in #1.
您现在可以改为旋转在#1 中创建的GameObject.
You can now rotate the GameObject created in #1 instead.
尽管,我讨厌这样做,但它也可以工作.我建议使用3D应用程序来移动轴心点.
Although, I hate doing that but it works too. I suggest using a 3D application to do it to move the pivot point.
这篇关于更改GameObject轴心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!