# The REAL size of an object.

 0 I know the rough size of an object can be calculated from the collider.bounds, but I want to know if there is a way to get the correct width/bounds of an object, for a sphere collider that would be the radius, for a box, it would be the extent (or the bounds if possible). The reason I want this is because I'm building an RTS game which need to show the life of each object, currently I'm using collider.bounds, but it doesn't work so well because the width changes every time I rotate the object. I can probably just do a lookup on what collider and it is and go from there, but that would require some Collider as BoxCollider stuff, which isn't go so easy on the CPU if you got a lot of units. Does anyone know how to do this? more ▼ asked Nov 18 '09 at 07:25 PM TowerOfBricks 3.2k ● 17 ● 25 ● 50 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 The reason the bounds size changes when you rotate the object is that the bounds represents an Axis-Aligned Bounding Box (also known as an "AABB"). If you want to get a bounding sphere, you could scan through all the object's mesh vertices to find an average vertex position (the sphere centre) and the vertex which is furthest away from the average, (which gives you the sphere's radius). See the Mesh Documentation for an example of how to quickly loop through every vertex in your mesh. There's a chance that your average vertex position may not be at your object's local (0,0,0) position, so you'll need to use Transform.TransformPoint() to convert it to world-space to find your real boundingsphere centre point for the gameObject. You then have the object's bounding sphere centre position and radius! more ▼ answered Nov 18 '09 at 08:52 PM duck ♦♦ 41k ● 92 ● 148 ● 415 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Is there some reason mesh.bounds won't work for you? more ▼ answered Nov 18 '09 at 11:37 PM Jessy 15.6k ● 72 ● 95 ● 196 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x5099
x1882
x389

asked: Nov 18 '09 at 07:25 PM

Seen: 6675 times

Last Updated: Nov 18 '09 at 07:25 PM