Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

[OPEN SOURCE]Procedural Hexagon Terrain

Discussion in 'Community Learning & Teaching' started by landon912, Mar 10, 2014.

  1. fialle

    fialle

    Joined:
    Aug 26, 2015
    Posts:
    1

    Hi Landon ! Thanks for the tutorial. From what i understand the code should be something like this:
    Code (CSharp):
    1.     public HexChunk GetHexFromWorldPosition(Vector3 worldPosition)
    2.     {
    3.         HexInfo hexToReturn = null;
    4.         float minDistance = 100;
    5.        
    6.         foreach (HexChunk chunk in HexChunk)
    7.         {
    8.             foreach (HexInfo hex in chunk.hexArray)
    9.             {
    10.                 //find lowest distance to point
    11.                 float distance = Vector3.Distance(hex.worldPosition, worldPosition);
    12.                 if (distance < minDistance)
    13.                 {
    14.                     hexToReturn = hex;
    15.                     minDistance = distance;
    16.                 }
    17.             }
    18.         }
    19.  
    20.     }
    And I have to replace " worldPosition " for my imput position right ? And then make worldPosition equal to hex.worldPosition for my object to move to that place.
     
  2. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,572
    Why did you change it to HexChunk and HexInfo? They're more internal classes. You should be dealing with Chunk and Hex.

    And the method will return the closest Hex, so yes, you'd want to move to that hex's worldPosition.
     
  3. Adventure-Forge-Studio

    Adventure-Forge-Studio

    Joined:
    Jan 13, 2015
    Posts:
    163
    I know you've left this thread to die, but if you ever find the time it would be greatly appreciated if you went through generating a random perlin map and assigning textures with it.
     
  4. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,572
    I would love too, unfortunately my time is just so limited nowadays and will be for the far future. :( The very small amounts of free time I have, I want to be as far away from technology as possible and get outside. Just run or something.
     
  5. Skaeren

    Skaeren

    Joined:
    Feb 9, 2015
    Posts:
    14
    This is a great tutorial, thanks for it!

    I have 2 questions though:

    1) How do I go about messing with each individual hex within a chunk?
    2) Any chance you could knock up some playmaker actions to work with this?
     
  6. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,572
    Hey there, thanks for the kind words.

    1) You would access the hex through one of the methods akin to GetHexFromWorldPosition as described from above. From there you have free reign over what you do with it. You can look at my repository for a more detailed explanation, but you'll have to dig through it yourself.

    2) I have neither the time nor Playmaker to do so unfortunately.. I don't think it'd be overly useful either as my WIP is defunct and shouldn't be treated as production ready. Therefore, adding Playermaker actions support doesn't make it anymore usable.

    Again, thanks for stopping by and the kind words.
     
  7. zaka221

    zaka221

    Joined:
    Jan 27, 2013
    Posts:
    3
    Any advice here?

    Couldn't get a value from the given key: Tundra setting to default : Grass/n Add this to the texture atlas!
    UnityEngine.Debug:LogError(Object)
    CivGrid.ExtensionMethods:TryGetValue(TileItem[], Tile, Rect&) (at Assets/CivGrid/Core/Scripts/Terrain/Utility.cs:651)
    CivGrid.InternalHex:AssignUVToDefaultTile() (at Assets/CivGrid/Core/Scripts/Terrain/InternalHex.cs:740)
    CivGrid.InternalHex:GenerateCustomHexMesh(Boolean) (at Assets/CivGrid/Core/Scripts/Terrain/InternalHex.cs:578)
    CivGrid.InternalHex:MeshSetup() (at Assets/CivGrid/Core/Scripts/Terrain/InternalHex.cs:492)
     
  8. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,572
    The Tundra texture is missing from the atlas. You can make a new one from the menu at the top and make sure to add a texture for every tile you are using in the manager.