The bounds for the collision object are in world space and axis aligned (AABB). I need to get the 8 vertices of the real bounding box for a calculation, not axis aligned. I could get them easily transforming the local bounding box. Is there a way to get this?
Ok, found the solution.
The 8 points in world space of the mesh bounding box which is in local space, can be obtained as follows:
// var rb : Rigidbody
// var obj: GameObject
var mesh : Mesh = obj.GetComponent(MeshFilter).sharedMesh;
if(mesh){
var min = mesh.bounds.min;
var max = mesh.bounds.max;
var transform = rb.transform;
var point1 = transform.TransformPoint(Vector3(min.x, min.y, min.z));
var point2 = transform.TransformPoint(Vector3(min.x, min.y, max.z));
var point3 = transform.TransformPoint(Vector3(min.x, max.y, min.z));
var point4 = transform.TransformPoint(Vector3(min.x, max.y, max.z));
var point5 = transform.TransformPoint(Vector3(max.x, min.y, min.z));
var point6 = transform.TransformPoint(Vector3(max.x, min.y, max.z));
var point7 = transform.TransformPoint(Vector3(max.x, max.y, min.z));
var point8 = transform.TransformPoint(Vector3(max.x, max.y, max.z));
}
Yes, but it seems the problem here is, this only works as expected if the mesh itself is AA (axis-aligned) when imported (or if it is a Unity Primitive...like a Cube). If it is not, it seems that the world-space bounding-box will not "fit" the object like you would expect. In other words, it seems like the renderer.bounds are basically the same as what the above post gives you...the local-to-world translated mesh bounds. I could be missing something, but IF this is the case, I have to say this is not useful at all.