How to make Grid with Hexagons (in angle)
Hi there! I need to make some kind of grid with hexagons (from there ill make and editor for those ones).
These hexagons sprites are in angle 65 degrees or so (this is just the Sprite, not rotation). https://pasteboard.co/HMdArHO.png
What Ive tested: -Project from v.zero to its angle applying distance -Arrange measuring offsets in each direction.
I kinda make it work, but in a real messy way and would like if someone could lead the way here to really undestand how this should be done.
Thanks in advance
Comment
Answer by luquio · Nov 13, 2018 at 01:41 PM
SOLVED: 1st calculate each row initial position. 2nd. Then por each row créate an hexagon and from there apply its stack position.
public void CreateHexagonGrid() { _startPos = StartPosition;
// Use width to calculate start position
for (int w = 0; w < Width; w++)
{
// To make it a little more "Squarish" like
if (w % 2 == 0)
{
_startPos += _tr;
}
else
{
_startPos += _br;
}
// Use height to calculate stack position (from start position)
for (int h = 0; h < Height; h++)
{
var pos = _startPos + new Vector2(_stackPos.x * h, _stackPos.y * h);
var go = Instantiate(Prefab, Parent);
go.transform.localPosition = pos;
go.GetComponent<SpriteRenderer>().color = new Color(Random.Range(0.25f, 0.75f),0,0);
}
}
}