GameObjects not rotating around axis, physics.

Hi, getting back in to unity after about 5 years. I scoured the web for the solution first but came up empty. I have an Asteroid that is made out of 8 separate parts. All the 8 parts have Rigidbody and I use the AddExplosionForce. It explodes fine but I want the parts to rotate using a Vector3. But the separate rock fragments are not rotating on their own axis, The axis they are using is offset so it looks like it is orbiting like the moon around the earth. I thought I could reset the axis but no luck. Goal is to have a ship shoot the asteroid and it explode in to its smaller spinning bits. Any ideas on fixing this is much appreciated. I included a photo too, that that it shows any movement. I should also note, I have IsTrigger check box turned on. If I turn it off, the object explodes by itself, but when it explodes by itself, the fragments spin correctly.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RockExplodeScript : MonoBehaviour
{
    public GameObject AxisParent;
    float timer = 0;
    bool hasExploded = false;


    // Update is called once per frame


    private void FixedUpdate()
    {
        timer += Time.deltaTime;
        if (timer > 1 && hasExploded == false)
        {
            hasExploded = true;
            ExplodeRock();
        }
    }

    private void ExplodeRock()
    {
        foreach(Transform t in gameObject.transform)
        {
            var _rb = t.GetComponent<Rigidbody>();
            if(_rb != null)
            {
                print("Name: " + t.name);
                _rb.AddExplosionForce(30f, AxisParent.transform.position, 10f );
                _rb.ResetCenterOfMass();
                _rb.AddTorque(new Vector3(2f, 3f, 5f), ForceMode.Impulse);
            }
         
        }
    }
}

This would be due to the center of mass on each Rigidbody not aligning visually with the mesh’s center of mass. Make sure the fragments’ pivots are correct and that the visual elements of the fragments match up with the colliders as well. Use gizmos to draw the center of mass if you want to see where it is.

Well, first of all, do not parent rigidbodies inside other rigidbodies. At least don’t have them active at the same time. Rigidbodies are generally simulated in worldspace. However if they are still a child of another rigidbody, the movement and rotation of that parent would also affect the child objects.

So you should unparent those objects when you blow it up. Unity even provides the Transform.DetachChildren method for such situations. Manually unparenting does also work. Though if you want to do it manually, be careful with loops over the children of the parent as you unparent them, the number of children changes.

1 Like

So these 3D objects each have there own fragments that have different pivot points. As I dug more in to it I noticed that I can switch from center to pivot and that showed me the point they rotate around (pivot) is offset from the Center. Doing research it doesn’t seem possible to shift the pivot point to the center. But is there ea way to rotate around the center, and not the pivot point of a GameObject?

I figured out the correct approach. I found the 3D assets and took them in to Cinema 4D. I adjusted each fragments axis to be the center and exported out a new fbx file. after re linking textures, creating new colliders it works. Thanks for your help. Also how do you switch from question to resolved?