Get apparent GameObject's height in global

Is there a way to reliably get the distance between top-most and bottom-most point of a GameObject including its children? I want to measure a human being which consists of several GameObjects and I need ability to subtract the highest point of the highest GameObject and the lowest point of the lowest GameObject and get its vertical distance in global space. If they’re standing it would be around 1.8 but if lain down about 0.3.

Neither test.transform.localScale.x amd test.GetComponent<Renderer>().bounds.size.x; fits the bill.

If you need to include children, you will need to write an algorithm for this. Start with:

Renderer[] childRenderers = GetComponentsInChildren<Renderer>();
foreach (var r in childRenderers) {

Check each r.bounds.yMin/yMax - track and find the lowest yMin and the highest yMax, then subtract them.

1 Like

Though I don’t know your specific use-case, which may call for the analytical method (eg. in a ragdoll game), in most cases I would suggest doing the “dumb” thing and hardcoding the expected values for standing, laying down, etc.

1 Like