- Home /
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.
Answer by Proportion1 · Mar 27, 2013 at 12:22 AM
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?
Answer by robertbu · Mar 27, 2013 at 03:22 PM
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;
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?
Your answer
Follow this Question
Related Questions
Waypoint To Ignore Height & Add Smoothness 5 Answers
Is it possible to generate a high-poly spherical model from a mercator-projection heightmap? 1 Answer
Same button position in all Android devices 2 Answers
How can I get the height of a sprite? 1 Answer
Is it possible to adjust an Objects pivot without affecting any of the child objects? 1 Answer