Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Generate Irregular Hexagons

Discussion in 'Scripting' started by seeliespright, Mar 31, 2024.

  1. seeliespright

    seeliespright

    Joined:
    Jun 29, 2022
    Posts:
    16
    I want to create a mesh the same shape / divisions of the image I attach below.

    I've looked all over the place, and primarily found procedural generation of hexagon maps, but I want irregular hexagons like the image I've provided. I attempted to understand and use Catlike Coding's tutorials on the various ways of generating and manipulating hexagons, including this one, which seems to be what I want: https://catlikecoding.com/unity/tutorials/hex-map/part-4/ but I can't understand it, or get their example projects to work.

    Can anyone point me toward some way I can generate this mesh through C#, or maybe even a relatively inexpensive Asset on the Unity Asset Store?

    I've already purchased the model meshes of what I've pictured, but I can't modify them.

    Many thanks!
    Screenshot 2024-03-30 at 4.26.48 PM.png
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    It's worth noting that the map you provided isn't irregular hexagons. It's irregular polygons of mixed numbers of sides. I see 4-, 5-, and 6-sided, at least. That's probably compromising your search results and might be clouding your logic trying to work out how to make it work.

    So are you looking for irregular hexagons (which the link you've given does generate), or irregular polygons (as in the image)? Or does it not matter, as long as the map doesn't look regular?
     
    Bunny83 likes this.
  3. seeliespright

    seeliespright

    Joined:
    Jun 29, 2022
    Posts:
    16
    Oh, thanks for pointing that out! I'm looking for irregular polygons then. I'm using it as a path, and I want it to look like irregular garden stones, as pictured.
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,495
    The word you're looking for is Voronoi. You pick random points that have a pleasing spacing, and then you construct an iso-distance edge between each pair of points, which ends up being a tiling of polygons. You can search for that word and find a TON of mathematics behind it, and several approaches to implement it.
     
    Nad_B, Ryiah and lordofduct like this.
  5. zulo3d

    zulo3d

    Joined:
    Feb 18, 2023
    Posts:
    1,054
    A problem I've noticed with procedural generation is that while it's possible to create a fancy procedure that can create a billion variations of something, the human brain will only be able to distinguish the difference between a small number of them.

    So in this case it may be better to manually create five versions and then just rotate them to add a little more variety.
     
    lordofduct likes this.