Search Unity

Hexagon grid overlay

Discussion in 'Getting Started' started by Zace666, Jan 12, 2016.

  1. Zace666

    Zace666

    Joined:
    Jan 28, 2014
    Posts:
    21
    Hi there,
    I've hot a mental block and I hope someone would be kind enough to help me out. I'm trying to generate a hexagon grid. Now before you all say there are loads of tutorial etc etc I have been through those and they all seem to be creating hex prefabs with 3d maps....
    I am after a simple grid that I can lay over a map. The map will be a 2d image scanned in - I am not (initially) generating the image, merely I want an overlay of line drawn onto an existing image.
    I assume I will have to load the image onto the surface of a box or something then add another layer so I can see a grid which will contain a coordinate system that I can then manipulate.
    Just wondering where to start.
    Thanks
    Z
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    If it were me, I'd try adapting one of those tutorials you looked at for my use. Just because they're creating hex prefabs with 3D maps doesn't mean YOU have to, right? You still want the hex, you just wouldn't give it any terrain or anything, and keep the height all the same (essentially making it 2D). Then the hex map is just an unstyled grid you can position on top of your textured plane or however you load your scanned texture.
     
    Ryiah likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Is the difficulty in the math — i.e., figuring out where the centers or vertices of the grid should be? Or is it in actually drawing them?

    And if the answer is "both," then which do you want to tackle first?
     
  4. Zace666

    Zace666

    Joined:
    Jan 28, 2014
    Posts:
    21
    All I want initially is to draw the 6 lines, turning 60 degrees each time to make the hex... I dont want to make 3d shapes, after all its going to be a grid overlay on a 2d map (I know its on a 3d shape but using a 2d orthographic camera)

    Next step would be to create an array to hold them
    then the items in the array could hold specific info - coords, hexNo, data, etc
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, well the easiest way to draw the hex would be to just make a transparent texture, and throw it onto a Quad (or Sprite or whatever).

    If that doesn't suit you, the next easiest way to draw them might be to use Vectrosity. It's really good at drawing lines.

    Or, you could make a 3D model of a hex outline using your favorite modeling program (I'm on a Mac, and love Cheetah3D).
     
    Ryiah likes this.
  6. M0nedula

    M0nedula

    Joined:
    Jun 18, 2020
    Posts:
    1
    I made a web app in Blazor that allows you to upload any image and then draw a hexagon grid over it; customizable hexagon size, line thickness and line color.
    For the moment there is no readme (planning on that, so check out the link for any updates!). The simple way at this moment is: open Visual Studio (or install the community version), clone the repository and run it.

    You can find the repository here: https://github.com/Monedula1/OverlayGrid

    Added an example of a 30 pixel diameter white line (1 pixel thick) hexagon grid drawn over a random image.
     

    Attached Files: