Advertisement
Deozaan

PlaceCenterAtOrigin.cs

Mar 14th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. public class PlaceCenterAtOrigin : MonoBehaviour {
  5.  
  6.     [MenuItem("GameObject/Place Center at Origin")]
  7.     static void PivotFixer() {
  8.         Transform child = Selection.activeTransform;
  9.         //Vector3 diff = child.rigidbody.worldCenterOfMass
  10.         Rigidbody tempRB = child.gameObject.AddComponent<Rigidbody>();
  11.         MeshCollider tempMC = child.gameObject.AddComponent<MeshCollider>();
  12.  
  13.         child.position = Vector3.zero;
  14.         child.position = -child.rigidbody.worldCenterOfMass;
  15.  
  16.         if (child.parent) {
  17.             child.position += child.parent.position;
  18.         }
  19.  
  20.         DestroyImmediate(tempRB);
  21.         DestroyImmediate(tempMC);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement