Hey there!
So I have an array of Transforms which are hexagon based tiles. They get instantiated in a pseudo-random, but always adjacent to each other. I also have a sphere/circle that is positioned to the center of all those tiles by taking the average of all those Transforms positions. (See link for clarification) 1
What I’m trying to do now is expand that red sphere/circle so that it encompasses all those Transforms, basically creating a perimeter around all the tiles. I was wondering how you would approach a solution, because I’m drawing blanks.
Thanks in advance!
I do not know how your code is set up, so this may not fit exactly, but hopefully it will get you moving in the right direction.
// The number of hexagons on the screen.
int numHexOnScreen = 0;
// The position of the cicle base on hexagon tranforms.
Vector2 circlePos = new Vector2();
// The radius of the cicle.
float radius = 0;
void Update()
{
// First, add a hexagon and increment numHexOnScreen.
AddHexagon();
// Then, calculate the new position of the cicle.
FindCirclePos();
// Finally, increase the radius if needed.
FindRadius();
}
void FindRadius()
{
// The distance between the circle's position and the position of the newest hexagon.
float proposedRadius = Vector2.Distance(circlePos, hex[numHexOnScreen - 1]);
// If the proposed radius is greater than the current radius, expand the current radius.
if (radius < proposedRadius)
radius = proposedRadius;
}