How can I find an object's height?

How can I find an object’s height in the world coordinates? I want to use the height mainly to subtract from the object’s current y-position in the world coordinate. Hence, the height has to be in the same metrics as the position vector. I tried localScale but it doesn’t work correctly.

2 Answers

2

i know my answer sounds a bit wrong but i would add 2 emptys to the object your trying to find the height for (one on the top of it and one at the bottom). then just do

Vector3.Distance(top, bottom);

But this would mean I have to add 2 empties for all the objects I want to find their height. And my code would always have to check if the 2 empties are there because I could find the height.

does the height of the objects change at all? if not couldn't you just have a float that represents each objects height?

Take a look at Renderer.bounds. This is the bounding box in world space around your object. You should be able to get the size by:

var height = renderer.bounds.extents.y * 2.0;

Why am I always getting zero for using bounds.extents.y?

Don't know. I played around and couldn't get extents.y to produce anything but the correct value, even if the object was out of the camera view and/or the renderer was turned off. Are you sure you don't have it attached to an empty game object?