Getting the position and rotation of objects making up a character mesh
Hello, thanks in advance for the help, and I'm sorry if this is a dumb question.
I am trying to make a script for the destruction of an enemy, I want the character to fall apart into pieces on death (it's a rock golem). The mesh is broken up into component pieces such as, head, chest, hips, upper arms, lower arms, feet, etc. and I am replacing them with an unrigged version of just the components, I added rigid bodies and colliders to these. It's sort of working, its replacing all the component pieces but sending them to the center of the rigged model, with the rotation of the rigged model. Is it possible to get the position and rotation of each individual piece? In the inspector when clicking on an individual piece of the rigged mesh, the position and rotation are shown as 0,0,0 across the board, but the overall character has its own position and rotation.
My script is below:
public class Destruct : MonoBehaviour { [SerializeField] public List Map;
public GameObject Bodyparts;
public GameObject AnimatedModel;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (AnimatedModel.activeSelf)
{
Bodyparts.SetActive(true);
destruct();
AnimatedModel.SetActive(false);
}
else
{
AnimatedModel.SetActive(true);
Bodyparts.SetActive(false);
}
}
}
public void destruct()
{
foreach (var keyval in Map)
{
var key = keyval.Key.transform;
var val = keyval.Value.transform;
val.position = key.position;
val.rotation = key.rotation;
}
}
}
[Serializable]
public class GameObjectKVP
{
public GameObject Key;
public GameObject Value;
}
Thanks again, I really appreciate all the help.