Change Pivot from Script( RunTime )

Hi, I want to change pivot runtime. Is possible to change and how to do it?

In order to change the pivot, you have to change the vertices in the mesh. Note you want to make a copy of the mesh before making these changes or you will likely end up make permanent changes to the mesh when you run your app in the editor. The first time I played this this kind of thing I ended up with permanent changes to Unity’s built-in sphere and cube.

#pragma strict

function Start () {
	var mf = GetComponent(MeshFilter);
	if (mf != null) {
		var mesh = Instantiate(mf.mesh); // Create a copy
		mf.mesh = mesh;
		
		var vertices = mesh.vertices;
		
		for (var v : Vector3 in vertices) {
			v.y += 0.25; 
		}
		
		mesh.vertices = vertices;
		mesh.RecalculateBounds();
	}
}

Note this change will not be reflected in the collider. If you object has a collider, you will need to make appropriate changes to it as well…move the center point or delete and then add a new collider.

You might also explore the SetPivot editor script:

http://wiki.unity3d.com/index.php?title=SetPivot