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.
Rotator Code:
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);
}
}
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);
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.
You can also use another GameObject as parent of this GameObject you want to rotate to solve this pivot issues.
1 .Create a new GameObject
2 .Move it to the center position of the object you are rotating.
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 .
You can now rotate the GameObject created in #1 instead.
Although, I hate doing that but it works too. I suggest using a 3D application to do it to move the pivot point.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.