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);
}
}
}
}
