- Home /
Changing the pivot point of meshes.
New to Unity and 3d graphics here so bear with me as I try to ask what likley amounts to a really silly question
I have a tank model who's turret I am trying to rotate, however its pivot point is not set correctly so the turret rotation seems off.
I know for transformation you can set the Pivot to center of the mesh or to the actual pivot point, but is it possible to change the pivot point ourselves inside Unity Editor?
Answer by Ben Throop · Jan 17, 2010 at 03:00 AM
This guy wrote an editor script to allow the user to edit an object's pivot location. Currently it's limited to within the object's bounding box, but he says this is fixable.
Link: http://solvethesystem.wordpress.com/2010/01/15/solving-the-pivot-problem-in-unity/
I hope this script helps someone else: http://unifycommunity.com/wiki/index.php?title=Pivot$$anonymous$$anager I tried to simplify that VoxelBoy's original SetPivot for my own understanding of it.
New wiki link is:
http://wiki.unity3d.com/index.php/Pivot$$anonymous$$anager
Answer by jashan · Nov 01, 2009 at 10:23 PM
As far as I know, this is not possible within the editor. It may be possible to do this with scripting and in that case you might be able to write some sort of editor script that does this for you - but in general, I think the best solution for this is using a modelling tool. Given the smooth asset pipeline in Unity, that's usually "almost as efficient" as if you would be doing it inside Unity itself. And ... given that this is something that usually an artist would do, I think it's even more efficient to do it in the modelling tool (as the artist will usually know how to do it there).
Thanks for the clarification. I currently don't have any 3d modeling knowledge but I should get that soonish.
Answer by Martin Schultz · Nov 03, 2009 at 02:40 PM
It's yet not possible to set the pivot directly in the editor. Only way around is to attach your object to a new gameObject and set the your object's local transform in relation to its new parent so that the pivot gets moved.
How to do this in practice? Do you have to script or something or can you do it in editor?
No it should not for several reasons:
First of all it's not your question but the question of abdullah.ahmed and he decides that Jashans and Ben Throobs answer answers his question.
This answer, even it's of course the most used workaround, does not really solve the problem of moving the pivot point. There are more reasons why you need it at a different position. For example a shader still get the local vertex positions of the original mesh. It's just the $$anonymous$$VP matrix which projects the vertices to their final position based on the Transform hierarchy. However if you need proper local coordinates you have to actually change the local positions of the vertices.
Ben Throob and Jashan do provide the proper answers to the actual problem. In short: It's not possible out of the box in Unity; It should be fixed in the modelling tool; Or you can use an editor script to fix it.
So while this answer clearly seems to be more helpful to most people, it's still the question of abdullah.ahmed.
Answer by venkspower · Nov 25, 2011 at 12:35 PM
It is not possible in the editor. Instead set an empty GameObject, and apply a box collider for that. And make that the parent object. And then try to rotate. But set the position of the object correctly. And adjust the scaling size to 1:1:1.
It may probably help you.
Answer by LifeSizeDeity · Aug 06, 2010 at 06:17 PM
I'm terrible at describing things, so I'll just give a code snippet. The long and short of it is, use transform.RotateAround function.
public class RotateAroundObject : MonoBehaviour {
private GameObject torret; private GameObject tankPivot;
private float rotateValue = 0;
Vector3 pivotTransVector;
// Use this for initialization void Start () { torret = GameObject.Find("torret"); tankPivot = GameObject.Find("tankPivot");
pivotTransVector.x = tankPivot.transform.position.x;
pivotTransVector.y = tankPivot.transform.position.y;
pivotTransVector.z = tankPivot.transform.position.z;
}
// Update is called once per frame void Update () { //Just an incremented value to rotate by rotateValue += Time.deltaTime;
//This will rotate around the x, you would need to change this
//to whatever axis the tank follows
scriptText.transform.RotateAround(pivotTransVector, Vector3.right, rotateValue);
}
}
Hope this helps a little
RotateAround is the key.
function RotateAround (point : Vector3, axis : Vector3, angle : float) : void
"point" is where your pivot point is. If you're not sure, you can create a small object and drag it to where you want and use the Inspector to get the coordinates. Put the coordinates in your code and delete the object.
Your answer
![](https://koobas.hobune.stream/wayback/20220613160107im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Does using "half res" in the quality settings reduce texture RAM usage? 1 Answer
Android device graphics problem !!! 1 Answer
Unity equivalent of ARB_occlusion_query (glGetQueryObject)? 0 Answers
Why does my game require so much rendering power? 1 Answer
Does Unity support NVIDIA frame synchronizing technology? 1 Answer