9.1 C
New York
Friday, March 14, 2025

unity – Easy methods to calculate the border hexagons in a grid with blocking components?


I’ve a hexagon grid with cubic coordinates. I wish to calculate clockwise all border hexagons for a given motion vary. In the intervening time, I’m iterating each neighbor that isn’t within the vary and isn’t blocked. If a hexagon has such a neighbor, it’s a boundary hexagon:

public void HighlightBorder(Listing totalRange)

This leads to the next:

(yellow begin, grey = blocked, pink = border, motion vary = 6)

Many border hexagons are lacking, as they’re both not bordered in any respect or solely with blocked hexagons. The specified result’s this:

enter image description here
(yellow begin, grey = blocked, pink = border, motion vary = 6, inexperienced = lacking border hexagons)

How can I obtain this?

I’ve already tried to seek out all excessive factors (lowest y, highest z), (highest x, lowest y) and so forth. and rotate from a beginning excessive within the respective path. For instance, I begin on the lowest z, highest x hexagon and transfer within the path (-1,1,0) till I discover the bottom z, highest y hexagon and proceed from there with the corresponding path.

I attempted to make use of the gap to the middle hexagon. I begin with the hexagon that’s furthest away, iterate every neighbor and proceed with the subsequent hexagon that’s furthest away. This works for a standard grid, however not for one with blocked hexagons or the instance proven.

I assume there have to be a comparatively easy algorithm, equivalent to “all the time to the suitable, backside proper, backside left, and so forth”.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles