- Home /
How do I get bounds or width/height of grouped objects?
Hi, Is it possible to get height and width of grouped objects like this?
I tried boxcollider2d.bounds and renderer.bounds. Each shapes in the group has collider component.
Is it possible?
screen-shot-2016-05-03-at-212957.png
(4.6 kB)
Comment
Answer by FortisVenaliter · May 03, 2016 at 07:28 PM
Basically, you need to loop through the bounds or vertices (depending on the level of precision and optimization you need) and get the min/max values for all of them in every dimension you use (Vector2 for 2D, Vector3 for 3D, etc). Something like this (pseudocode, won't compile):
Vector2 min = Vector2.MaxValue;
Vector2 max = Vector2.MinValue;
foreach(Object obj in AllObjects)
{
min = Min(min, obj.Bounds.Min);
max = Max(max, obj.Bounds.Max);
}
Then the min and max define an AABB that will bound all of your objects.