title: How to set center of gravity on prefab child?
body: <p>I have a 3d model prefab in unity that I'm trying to add physics to. The issue is that the prefab was imported from auto desk and when that happened the pivot/center of gravity for all the child mesh objects was not where you would necessarily expect them. I've tried attaching a rigid body to the various child objects and setting the center of mass with a script but it doesn't seem to be working as I would expect. My method for setting the center of mass involved creating two child game objects at either end of the highlighted object and using the midpoint formula to a 'good enough' center of mass. Is there any way around this beyond rebuilding/re-importing the object?</p>
  <p>Showing the off center pivot</p>
  <p><a href="https://i.stack.imgur.com/VfWOf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VfWOf.png" alt="" /></a></p>
  <p>Showing the weird center of mass</p>
  <p><a href="https://i.stack.imgur.com/P8GfI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P8GfI.png" alt="" /></a></p>
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class CenterOfGravity : MonoBehaviour
  {
      // Start is called before the first frame update
      public Transform[] centerPoints;
      public Rigidbody rb;
      void Start()
      {
          centerPoints = gameObject.GetComponentsInChildren&lt;Transform&gt;();
  
  
          Transform center1 = Array.Find(centerPoints, elem =&gt; elem.name.Equals(&quot;Center1&quot;));
          Transform center2 = Array.Find(centerPoints, elem =&gt; elem.name.Equals(&quot;Center2&quot;));
  
  
          Vector3 center = (center1.localPosition + center2.localPosition)/2.0f;
  
          rb = GetComponent&lt;Rigidbody&gt;();
          rb.ResetCenterOfMass();
          rb.centerOfMass = center;
  
      }
  
      // Update is called once per frame
      void Update(){}
  }
  </code></pre>