Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- public class PlaceCenterAtOrigin : MonoBehaviour {
- [MenuItem("GameObject/Place Center at Origin")]
- static void PivotFixer() {
- Transform child = Selection.activeTransform;
- //Vector3 diff = child.rigidbody.worldCenterOfMass
- Rigidbody tempRB = child.gameObject.AddComponent<Rigidbody>();
- MeshCollider tempMC = child.gameObject.AddComponent<MeshCollider>();
- child.position = Vector3.zero;
- child.position = -child.rigidbody.worldCenterOfMass;
- if (child.parent) {
- child.position += child.parent.position;
- }
- DestroyImmediate(tempRB);
- DestroyImmediate(tempMC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement