- Home /
Cannot rotate an object around the center
I got some answers from the forum and tried them all. Still doesn't work. I need to make the blades rotate, however it always rotate around some axis that is far from center which causes the blades far from the center.`Pig.transform.Rotate(Vector3.forward*(Time.deltaTime)*100);` I know this should be simple, but it just doesn't work. Also, I found something interesting. In the inspector, the position doesn't change at all though it should change. See the image.
Hmmm, Could you package it up in a unity package? I could take a look at it.
It's a project in the lab, may not be a good idea to release though. Sorry for that...
Answer by supernat · Mar 26, 2014 at 02:46 AM
Transform.Roate will not change position. It only changes the rotation of the object around its local origin, just to clarify your comment about why the position doesn't change in the inspector.
The key is the object's origin. The local model origin of an object (called the pivot) like this should be the geometric center but probably on the inside (back side) of the cap. There's a button on the top left of the editor (two buttons side by side). They say Pivot/Center and Local/Global. If you select Pivot Local, you should see the arrows of the blades right in the center of the cap somewhere. If the arrows are far outside this, when you rotate the blades, they'll rotate around those arrows (that's the model origin). You should play with these buttons and learn to use them, they will save you a lot of heartache.
There are three ways to fix this. 1) Re-export from the modeling software with the pivot point set to the cap of the blades. 2) Create an empty game object at the cap in the root of the scene hierarchy, drag the blades into that game object, and then rotate that game object instead of the blades. 3) Get a pivot modifier script from the asset store or write your own, and use it to move your pivot in the editor and re-save it.
EDIT: My answer is assuming your pivot is not located properly. If it is, then something else is amiss, maybe the blades are a child of a game object, and you are rotating that game object instead of the blades. Also, you should be able to select the blades, then modify the Rotation values in the Inspector's Transform. Once you get the blades rotating smoothly, you know you've got the correct center. Lastly, in the modeling software, an initial mistake I used to make was selecting all of the vertices/polys and moving them around instead of moving the object itself around. This places the verts off-center (they may all be around +10 for example instead of around 0. In 3DS Max, you can fix this relatively easy with the Hierarchy Modify Pivot panel.
Yeah, you are right! Thank you so much! Though the thing is that I load the obj file runtime, also it seems that in obj file there is no pivot variable. I think I may try to use method 2 and 3 to solve this. Thank you again!
I'm little confused about 2), what is the meaning of rotate the game object ins$$anonymous$$d of the blades, I created an GameObject Pig and moved it's pivot in the inspector and then use this`Pig=GameObject.Find("Nosecone");` to try to get the GameObject, however Nosecone still use the old pivot though. Could you give me some idea? Thank you so much!
Hmm, let me put this in perspective for you. So essentially let's take this as your object pivot:
Y
^OOO
|OOO
|XOO
.----->X
The "X" here being the "Pivot". Transform.Rotate will rotate around the X. But I am sure you get that by now.
Create an empty game Object, parent the object to the new game object. If you set the localScale of your windmill object to 0,0,0 the pivot(which is at the corner of your windmil) will be at the center of the new gameObject.
And because the corner of your windmil is now at the center of the parent gameobject, when you rotate the parent game object, it will rotate the entire object with the corner of the windmill being the center of the new gameobject.
I hope you understand that, if not try it out in Unity to get a grasp of what I am saying.
What you are meant to do, according to seanlitow's 2) is to positon the windmill such that the center of the windmill, not the pivot but the center you want, is at the center of the parent gameobject.
So taking C to be the center of the parent gameObject, in this X and Y representation it should look like:
Y
^OOO
|OCO
|XOO
.----->X
So in this case, the coordinate of the gameObject would be (0,0,0) but the coordinate of the windmill would be something similar to(-1,-1,0)
Explanation is messy but I hope you got that...
And then when you want to rotate the windmill, you rotate the parent gameObject ins$$anonymous$$d.
@supernat, thank you for your suggestion, I used the transform.RotateAround in a wrong way and now I use it again and it works. This function can change the pivot. Thank you so much!
Answer by pcdrive · Oct 04, 2016 at 07:25 PM
Hi dude,
You must have find the solution, but i run into the same problem and maybe someone else is looking for it too. Actually i made a simple mistake, and took 2 hour to get it since im a beginner.
When you make a prefab listen to the objects position, because the prefab's pivot will not be where the contained objects pivots are, but in 0,0,0. So if you make a prefab you should listen to where are the object are and move them to the 0,0,0, so the prefabs pivot will be at the center of the object.
This always need to be done. Reset the new parent GO before childing another.
Answer by giantkilleroverunity3d · Aug 25, 2016 at 02:53 AM
Using the two buttons in the upper left corner of the game editor can alleviate alot ot problems and questions. I just wish I found this two hours ago. I am using Probuilder to create complex models and need to exercise the transformers visually.
Answer by moritzcerst · Jan 26, 2021 at 06:21 PM
If you use ProBuilder, you can automatically adjust the pivot.
Answer by exactspace · Jul 29, 2021 at 04:03 PM
How do you adjust the pivot in Unity?
You can't. But there is a particularly easy way for that. Create an empty gameobject, and assign the object as it's child with an offset position to center it. Finally use the empty gameobject instead of the other. It's even easier if you make a prefab out of it