FX Hex Grid (Hex Grid Generator)

Discussion in 'Assets and Asset Store' started by ForceX, Oct 10, 2011.

  1. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    [​IMG]

    FX Hex Grid will generate a Hex based map using a base Hex geometry and an input for Map Height Width. Each Hex section will have a script component that contains its location in the map. Top left is 1,1.

    This is very basic and is intended as a starting point for Hex based map generation. Modify it to fit your game. Enjoy.

    Current Build Version 1.2.0

    New Features:
    1. Hex Map Wrapping - By enabling "Enable Wrapping" you will be able to create a hex map that seams to wrap around its x axis.
    2. Wrapped Hex Map Counting - when "Enable Wrapping" is enabled you will all ways be able to find out how far you are from a desired hex even when wrapping from left to right or right to left.
    3. Able to set initial camera height.
    4. Able to set initial camera angle.

    Changes:
    1. Keep Symmetrical will be set to disabled if Enable Wrapping is enabled.

    Setup
    1. Create an empty gameObject and apply the script FX_HexMapGen.js
    2. Apply the Hex prefab to the FX_HexMapGen --> Hex Grid
    3. Set the FX_HexMapGen --> Map Width Height
    4. Run

    Tip:
    1. For non joining maps enable Keep Symetrical. This will keep the edges of the map the same.
    2. While in the unity editor generating a large map 200 x 100 will take a minute to compute. Outside unity in a compiled state this is much faster.

    WebPlayer DEMO
    This demo shows a grid generated at a size of 20x10 with Keep Symmetrical enabled.

    [​IMG]


    HOT FIX

    Edit the FX_Map_Manager.js and replace the function CalculateDistance() with :

    Code (csharp):
    1. function CalculateDistance(){
    2.  
    3. var dx : int = Mathf.Abs(GoToHex.x - CurrentHex.x);
    4. var dy : int = Mathf.Abs(GoToHex.y - CurrentHex.y);
    5. var dz : int = Mathf.Abs(GoToHex.z - CurrentHex.z);
    6.  
    7. var DistA : int = Mathf.Max(dx, dy, dz);
    8. var DistB : int = Mathf.Abs(DistA - Mathf.Abs(MapSize.x + dy));
    9.  
    10.     if(EnableWrapping){
    11.         if(dy > DistB){
    12.              Distance = Mathf.Min(DistA, dy);
    13.         }else{
    14.              Distance = Mathf.Min(DistA, DistB);
    15.         }
    16.     }else{
    17.         Distance = DistA;
    18.     }
    19. }

    Internet Explorer 9 users. If you are having problems downloading files from the fourm please enable Compatibility View

    Attached Files:

    Last edited: Jan 11, 2014
  2. SeanP

    SeanP

    New Member

    Joined:
    Feb 27, 2011
    Messages:
    38
    This is pretty awesome. Good work!
  3. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Thanks :) . The next step is to address the hex grid to an array so it can be accessed by other elements such as an "Ai". For those who know more than I; should have no problem with this. Right now I'm kinda making it up as I go along.
  4. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    New Build 1.1.0

    New Features
    1. Distance counting : This new implementation will find the distance from any one Hex to any other Hex on the map.

    Changes:
    1. Changed the way hexes are numbered. New system uses a vector3 instead of a vector2.
    2. Hex 0,0,0 is now the bottom left

    Updated WebPlayer DEMO

    You can click on a Hex to set it as your current position hex and then move the mouse over other hexes to see the distance to that hex. Your starting hex is 0,0,0.

    Phew.. Creating that distance counter was a new experience, i learned quite a bit about how to use some Mathf functions that i haven't had the opportunity to use before; even if they are not the ones i ended up using in the code. Much fun was had.
    Last edited: Oct 13, 2011
  5. g00niebird

    g00niebird

    New Member

    Joined:
    Jul 24, 2010
    Messages:
    281
    The vector3 numbering scheme is a bit confusing. Is there a reason you moved from a 2D system?
  6. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @ g00niebird : Yes. The Vector3 makes distance calculations very easy as it's now the Max of the Abs value of the difference of x -x or y - y or z - z.
    The z you will notice is just a the negative value of x + y with in that cell. X Y are still your position within the grid. Z is only used for distance calculations. I'll post up a new image demonstrating this a bit later, but i'm off to work right now. You can check out this PAGE for more info.
  7. Tasarran

    Tasarran

    Member

    Joined:
    Jan 20, 2011
    Messages:
    302
    Have you seen my HexTech framework?
  8. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    I have. This project is more for my experience in scripting than any thing else.

    Next update: (This weekend)
    1. Camera will scroll around the map creating a wrapping effect.
    2. Counting across a wrapped map.
  9. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    New Build 1.2.0

    New Features:
    1. Hex Map Wrapping - By enabling "Enable Wrapping" you will be able to create a hex map that seams to wrap around its x axis.
    2. Wrapped Hex Map Counting - when "Enable Wrapping" is enabled you will all ways be able to find out how far you are from a desired hex even when wrapping from left to right or right to left.
    3. Able to set initial camera height.
    4. Able to set initial camera angle.

    Changes:
    1. Keep Symmetrical will be set to disabled if Enable Wrapping is enabled.

    Known issues:
    1. For some reason the camera seams a bit jerky at times. I'm not sure why atm.

    Updated WebPlayer DEMO to latest build.

    This is a first attempt at creating a wrapping world. It's not perfect but it's close enough for a release. This is something i will continue to work on.


    Previous Updates

    Version 1.1.0
    New Features
    1. Distance counting : This new implementation will find the distance from any one Hex to any other Hex on the map.

    Changes:
    1. Changed the way hexes are numbered. New system uses a vector3 instead of a vector2.
    2. Hex 0,0,0 is now the bottom left

    Version 1.0.3
    Changes:
    1.Changed the orientation of the Hexagon. This makes counting much easier and the map neater.


    Version 1.0.2
    New Features:
    1. Keep Symmetrical. This option will keep the edges of the map symmetrical.

    Version 1.0.1a
    New Features:
    1. Added simple mouse hex highlight interaction.
    2. Added hex tile template texture.

    Fixes:
    1. Corrected an issue with row / column counting.
    Last edited: Feb 20, 2012
  10. vonWolfehaus

    vonWolfehaus

    New Member

    Joined:
    Oct 14, 2011
    Messages:
    2
    This is really great, thanks so much for sharing it!

    I'd like to use this in my first Unity project, a hex-based Risk clone. Would I be able to alter the scripts to allow me to manually place hexes in a grid (via the editor)? I'm still catching up on Unity-based development.
  11. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Yes. You can modify the scripts as you see fit for your game.
  12. nagata

    nagata

    New Member

    Joined:
    Dec 24, 2011
    Messages:
    99
    is it possible to elevate hex blocks?
    any chances for AI for this thing?
  13. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @nagata: I don't see why you couldn't elevate the hex. Though the hex is just a flat plane, there would be nothing under it. You would have to either bring in your own 3D hex and adjust the vertices for your height. Or make some type of mask to cover up the empty space below the hex. I'm sure there are lots of ways.

    As for Ai. Not any time soon. I only created the hex board as an experiment. Mainly to understand how to count hexes. The math to get from one hex to the next is in the code so it should be able to be re-purposed for an Ai. As long as the Ai knows which hex it's on and what hex it wants to get to. For that you would want to create a table of the hexes that contains its position, land type, and any resources. Then the Ai could look at the table and say "i want to get to hex blah, blah". You would also want a movement counter to check how many more moves you have.
    Last edited: Feb 20, 2012
  14. Mingo

    Mingo

    New Member

    Joined:
    Nov 14, 2010
    Messages:
    39
    Hey, excellent work! I prefer this coordinate system for hexes, as it makes things like pathfinding (which I've added to this easily!) much simpler.

    One question though, assuming you're still working on this: do you have any suggestions for converting world coordinates (say from a camera->ground plane intersection) to hex coordinates? I'm interested in procedurally generating the hex meshes, or combining the meshes after instantiation and removing the gameobjects/colliders that are currently used for each hex. Having a GO/collider for tens of thousand of hexes just won't work without a paging/viewport system of some kind, but I'm stuck trying to figure out a formula to do mouse picking without the colliders.

    Thanks for any help, would love to see more updates to this project!
  15. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Mingo: I see exactly what your want to do but unfortunately i don't have an answer for you. I do seam to remember an article i read on the internet while i was searching for a method of counting across hexes. I think the article was using a pixel color look-up for hex position information from a flat plain / texture. I only think that is what the article was about. I didn't spend too much time reading it, i only thought it was interesting but out of my realm.

    One thing you could try would be a way to count to the center of a hex from wold space. If the center of a hex to any other hex is 1 unit then you could convert your X,Y world position to some Hex position.

    It would look something like:
    World position X=4 Y=0
    This would be the fifth Hex to the right of Hex 0,0.
    Hex Space = 4,0

    You would just need to figure out your vertical offset.
    You know that your first row of hexes is starting at 0,0. This makes the first row an even number. Then your second row 0,1 is an Odd number. Your odd row Hexes are off set by from the row above or below them by .5. So you would just need to check if your Y position is odd or even then adjust your Hex count based on this.

    It would look something like:
    World position X=4.5 Y=2
    This would be the fifth Hex to the right on the third row.
    Hex Space = 4,2

    Remember you are counting starting with 0. Visually 0 + 4 would be the fifth hex, but in an array it's stored as 4. Remember your array offset for a visual conversion.

    This is far from perfect as you would loose accuracy as you get closer to the edge of a hex.

    This is just an idea that with some work might be able to work. What ever you choose to do let me know if you get it to work the way you want. I would like to know. GL
    Last edited: Mar 23, 2012
  16. Mingo

    Mingo

    New Member

    Joined:
    Nov 14, 2010
    Messages:
    39
    There's probably a much simpler way to translate from hex to world coords and back, but the approach I'm taking for now is to plot a line in world space from hex[0,0] to hex[0, maxY] to simulate the hex Y axis. I then find the closest point on this line to the mouse cursor's world position. This gives me the Y coordinate in hex space. The distance of the point from the line gives me the hex X coordinate.

    http://www.topcoder.com/tc?d1=tutorials&d2=geometry1&module=Static for more info on it, especially "Line-Point Distance" algorithm on the page.
  17. MoPMetallica

    MoPMetallica

    New Member

    Joined:
    Jul 25, 2012
    Messages:
    13
    Could you explain in full how to apply this thing? Your setup isn't very clear on how to get the grid work. All I've got is one hex and when I try to get the game to play to test the hex out the game just keeps pausing. I can't find FX_Hex_Map_Gen or whatever.
  18. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Easy

    1. Create a new empty GameObject named "_MapMgr"
    2. Assign the script FX_Map_Manager to "_MapMgr"
    3. In the inspector assign:
    ....a : Cam 1- Is a camera
    ....b : Hex Grid - Is a mesh / prefab

    4. Set a value for Camera Height, Camera Angle, Camera Speed. Demo uses 3, 65, 2
    5. Set your Map Size.
    6. Run
  19. Bluevein

    Bluevein

    New Member

    Joined:
    Oct 26, 2012
    Messages:
    1
    This is amazing. Thanks for the great work. I only just started working with unity, but this will help a lot. Cheers.

    Quick question tho. Following just the instructions above and setting my Map size to 10,10 the distance calculation does not remain accurate. It seems to assume that Setting the active tile to 0,0,0 then moving your mouse across to 5,0,-5 measures a distance of 5, but moving any further across lowers the distance until at 9,0,-9 it assumes the distance is 1. It's like it is assuming it can wrap back around from 9,0,-9 to 0,0,0. I can get around that by simply creating my own distance measurement method, but I was just wondering why your default behavior acted in this way. (Note: I have Enable Wrapping and Keep Symmetrical both off).
    Last edited: Oct 26, 2012
  20. mamoniem

    mamoniem

    Member

    Joined:
    Jul 23, 2012
    Messages:
    131
    intersting tool as it becomes so important for lots of games :) i guess we will forget the square tiles soon :( i`ll miss them :p

    m;
  21. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    I have not look at this script in sometime. If that is the case then it seams like a simple if() check may be required for when Wrapping is not enabled so it wont execute the "Wrap math" when the last hex is selected. I'll have to look at it when i am at home and get back with you. It should be a simple fix, something like

    Code (csharp):
    1. if(EnableWrapping){
    2.  //do wrapping math
    3. }else{
    4. //do normal math
    5. }
    I just need to look at the code to see where this needs to be placed.

    I have not tried it my self but if anyone is looking for something more than simple grid layout and hex counting then go check out Tile Based Map Nav by Leslie Young. I think this looks like a good package has some nice features, so check it out if you need a more complete solution.
    Last edited: Oct 26, 2012
  22. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Bluevein : Thanks for reporting this bug! Here is the fix.

    Edit the FX_Map_Manager.js and replace the function CalculateDistance() with :

    Code (csharp):
    1. function CalculateDistance(){
    2. var dx : int = Mathf.Abs(GoToHex.x - CurrentHex.x);
    3. var dy : int = Mathf.Abs(GoToHex.y - CurrentHex.y);
    4. var dz : int = Mathf.Abs(GoToHex.z - CurrentHex.z);
    5.  
    6. var DistA : int = Mathf.Max(dx, dy, dz);
    7. var DistB : int = Mathf.Abs(DistA - Mathf.Abs(MapSize.x + dy));
    8.  
    9. Debug.Log("DistA : " + DistA + "   DistB : " + DistB + "  DY : " + dy);
    10.  
    11.     if(EnableWrapping){
    12.         if(dy > DistB){
    13.              Distance = Mathf.Min(DistA, dy);
    14.         }else{
    15.              Distance = Mathf.Min(DistA, DistB);
    16.         }
    17.     }else{
    18.         Distance = DistA;
    19.     }
    20. }
    I'll update the .unitypackage file this weekend.
    Last edited: Mar 31, 2013
  23. trumpets

    trumpets

    New Member

    Joined:
    Mar 1, 2013
    Messages:
    6
    Hi ForceX!

    The unitypackage located on the first page of this thread has some invalid code. For example the above code is written as
    Code (csharp):
    1. dx = Mathf.Abs(GoToHex.x - CurrentHex.x);
    without any variable declarations.

    Do you plan to update it?

    Thanks!
    /ivo
  24. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @trumpets: I take it that is from the calculate distance function. Check two post up and you will see a updated code that fixes an issue. Follow that post and see if it helps. I am at work ATM so there is not much I cad right now.
  25. EvansGreen

    EvansGreen

    New Member

    Joined:
    Nov 9, 2012
    Messages:
    128
    Out of curiosity, does this support multiple heights? Like creating a 3d hex board with multiple hex heights?
  26. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @EvansGreen : Not in its native state. This will only generate a flat map aka civilization style. I'm sure with some tinkering around you can create a map with height. You just need to adjust any given hex's Y axis to be + or -. And a custom hex that has hex walls to fillin the gap.
  27. EvansGreen

    EvansGreen

    New Member

    Joined:
    Nov 9, 2012
    Messages:
    128
    I understand, so basically it would be a 2d single plane map, that I would trick to make it look like 3d... sounds like a possibility.

    Thanks for the quick answer!
  28. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    While the map is a 3D object that consist of 3D hex fbx instances and can have the camera rotate around freely. The hexes them selfs are flat geometry. You will want to create a hex that is extruded upwards with its pivot point located at the bottom. This way you can just adjust the hex y scale value to create a hex that is tall or short.
  29. trumpets

    trumpets

    New Member

    Joined:
    Mar 1, 2013
    Messages:
    6
    Hi ForceX,

    It seems the scripts are fine, but Unity forces the #pragma strict when building for Android, which is what I was doing :) So basically I had to go through all of them and strongly type all the variable declarations. No biggies :)
  30. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    How would I have a game object follow this hex map by "snaping" to the hex rather then dragging them freely to where I want them. Also how do you set the camera to stop at the edge of the hex map border?

    Great work man, I'm sure this took a while to build. Just wanted to see that we appreciate you!
  31. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Razial7 : For snap placement you can set your gameObject.position = the target Hex.position. This would be the easy way with the current script. The script is already casting a ray to gather information from a script attached to the hexes. You can use this to get a hex world position as well with :

    hit.transform.position. That is what I think would be the easy way.

    For limiting the camera movement around the hex grid. Each hex is 1 unity unit , and I believe the grid starts to generate at world 0,0,0. You can do something like:

    var hexgridwidth : Vector2 = Vector2(hexgrid height, hexgrid width);
    If(camera.position.x < hexgridwidth.x){
    Move the camera.
    }

    Then do the same thing for the Z direction.
    Again these are the simple answer. Sorry if it seems short but I am typing this on my phone atm. Hope this helps some.
  32. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    Sorry Im a bit of a noob to this. Would I place the var to limit the hexgridwidth under update or updatecamera?
  33. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Razial7 : You would want to do it in the function UpdateCamera() or the function UpdateCameraW(). Depending on if you have Enable Wrapping turned on.

    function UpdateCamera() = non wrapping camera.
    function UpdateCameraW() = A camera that will wrap around the map along the horizontal direction.

    If you are not using wrapping then you will want modify this under the UpdateCamera()

    Code (csharp):
    1.    
    2.  
    3. // This is the cameras horizontal movement azis
    4. if(pos.x >= 1){
    5.     pos.x = 1;
    6.     MoveVector.x = 1;
    7. }else if(pos.x <= 0){
    8.     pos.x = 0;
    9.     MoveVector.x = -1;
    10. }else{
    11.     MoveVector.x = 0;
    12. }
    13.  
    14. // This is the camera's front / back movement axis.
    15. if(pos.y >= 1){
    16.     pos.y = 1;
    17.     MoveVector.z = 1;
    18. }else if(pos.y <= 0){
    19.     pos.y = 0;
    20.     MoveVector.z = -1;
    21. }else{
    22.     MoveVector.z = 0;
    23. }
    And do something like this.

    Code (csharp):
    1.    
    2.  
    3. // This is the cameras horizontal movement azis
    4. if(Cam1T.position.x < total map width || Cam1T.position.x > 0){ // Check if the camera is inside the maps width bounds.
    5. if(pos.x >= 1){
    6.     pos.x = 1;
    7.     MoveVector.x = 1;
    8. }else if(pos.x <= 0){
    9.     pos.x = 0;
    10.     MoveVector.x = -1;
    11. }else{
    12.     MoveVector.x = 0;
    13. }
    14. }
    15.  
    16. // This is the camera's front / back movement axis.
    17. if(Cam1T.position.y < total map height || Cam1T.position.y > 0){// Check if the camera is inside the maps height bounds.
    18. if(pos.y >= 1){
    19.     pos.y = 1;
    20.     MoveVector.z = 1;
    21. }else if(pos.y <= 0){
    22.     pos.y = 0;
    23.     MoveVector.z = -1;
    24. }else{
    25.     MoveVector.z = 0;
    26. }
    27. }
    If you are using camera wrapping then you will modify these in the function UpdateCameraW()
    Here you will only want to prevent the cameras Y position from exceeding the maps height as the X axis will wrap around the map.

    This code will not work right out of the box and i have not tested this. You need to create a var for total map height and total map width and store that information. This should get you started, and you may need to do more than what i posed above. I just don't have time to add this in right now. Let me know how it goes, and if you need any more help.
    Last edited: Mar 11, 2013
  34. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    Yeah I think it will work but need to figure out the brackets positioning. Its throwing errors below in the function below function Update() Ill try to figure out where to place and space. Thanks for the guidance.

    One last question...

    gameObject.position = the target Hex.position, how would go about this.... hit.transform.position?

    I dont follow this. if you have time later could you explain if I create a var that go = selectedhex or if its a bit more.

    thanks for all the help
  35. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    Okay quick update.. I got the campositioning to stop scrolling when you reach the end of the grid but the problem I have with it is the level begins with half the grid off screen and it will follow you to the tip of the last hex which is great but how can I set it to start the grid where I want it on the screen. if I only use 5x6 grids they will all fit in my window but I have to scroll them on the screen before it locks the screen in position,
    as well as the gameObject thing I mentioned before. If I figure it out first I'll let you know. Thanks
  36. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Razial7

    1. Positions : The FX_Map_Manager.js script uses a RaycastHit named MouseHex that is called in the function MousePosition(). In the if(Input.GetMouseButtonDown(0)) statement you can call the MouseHex.transform.position and do something like.

    Code (csharp):
    1. MyGameObject.transform.position = MouseHex.transform.position.
    This will set any gameObject's position of your choice to the position of the clicked hex.

    2. Camera Start Position : It sounds like you just need to adjust the cameras start position. Look in the function SetupCameras() and adjust Cam1T to any start position you like. Most of the code in there is for the camera wrapping. So if you are not using wrapping then you will be fine.
  37. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    Fixed both problem thanks a lot man you do great work!
  38. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Razial7 : Your welcome good luck with your project!
  39. Razial7

    Razial7

    New Member

    Joined:
    Oct 12, 2012
    Messages:
    59
    spoke to soon lol sent you a message
  40. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    If anyone is interested, I've created a script that will procedurally generate a Hex object with UV's.

    How to use it.

    1. Apply the included Hex Generator.js script to a gameObject in your scene.
    2. Create a material.
    3. Apply included Hex_Template.png texture to the material.
    4. Apply your material to the Hex Material field in the inspector from the gameObject you applied the Hex Generator.js script too.
    5. Run.

    This will create a single hex at runtime and apply the supplied material. Consider this a starting point for procedurally generating a hex based map with no external FBX resources. The idea behind this is; with the use of a height map and direct access to any given Hex's vertex information it should be possible to create a Hex based terrain. While this script only generates a single Hex, It seams to be a good starting point. Time will tell :)

    Attached Files:

  41. mikekeke

    mikekeke

    New Member

    Joined:
    Aug 23, 2013
    Messages:
    2
    this line is causing errors - I see that I'm not the only one to have this problem. I went through and put 'var' in front of each variable definition that was causing the errors and it compiled but when I play the camera scrolls off to the left. Am I missing something here - I really want this to work but it seems really buggy. Thanks for your efforts in writing and releasing this - hope I can get it to work.
  42. mikekeke

    mikekeke

    New Member

    Joined:
    Aug 23, 2013
    Messages:
    2
    Ok, the problem was - I was building for ios. If I build for web all work OK
  43. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Hmm that seams strange. Are you using the camera wrap around mode? All that line is doing is returning positive Int. I'm not sure why x - y would be any different across platforms. Any way glad you got it working.
  44. landon91235

    landon91235

    Member

    Joined:
    Nov 8, 2011
    Messages:
    940
    Nice work ForceX.

    [REMOVED]
    Last edited: Nov 12, 2013
  45. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    @Landon91235 : I'll give it a look after work today.

    Edit: Just to confirm is what I am looking for in the pic I posted below?

    Attached Files:

    Last edited: Nov 12, 2013
  46. landon91235

    landon91235

    Member

    Joined:
    Nov 8, 2011
    Messages:
    940
    Yes sir. Fortunately I fixed it all, just some variable typos.

    C# Version below:

    View attachment $FXGrid_C#ScriptsOnly.unitypackage
    Last edited: Nov 17, 2013
  47. ForceX

    ForceX

    Member

    Joined:
    Jun 22, 2010
    Messages:
    855
    Ok awesome.

    From the 2 min I was able to look at it this morning before work my first though was that it may just have to with the odd or even line generator getting the wrong info.

    Glad you were able to get it working :)
  48. kelbirk

    kelbirk

    New Member

    Joined:
    Jun 27, 2013
    Messages:
    5
    Landon, I started converting it to C#, but it looks like you've saved me some work. I have a couple of questions, though. Where are you getting the 'Unit' type from? Unity isn't recognizing it. And what's the purpose of the random arrays for HexGrid? That has me totally confused.
  49. landon91235

    landon91235

    Member

    Joined:
    Nov 8, 2011
    Messages:
    940
    Hehe sorry. You can delete any and all "Unit" references as they were some work that I guess leaked into the project. The random arrays for the hex grid is my own modification so that you could use multiple versions of the grid if needed. It should be fairly easy to edit out of there.

    I'll edit the project code ASAP to reflect this.
  50. kelbirk

    kelbirk

    New Member

    Joined:
    Jun 27, 2013
    Messages:
    5
    I've run into an issue with trying to implement this grid into an actual game, and I'm wondering what others have done to work around it. In this script, the grid instantiates at run time. This didn't seem like it would be a problem until I added actual units into the game. Now, when I want to drag GameObjects/units onto the public variables, as Unity so wonderfully allows, it won't allow it/keep it. How can I attach units to specific hexes when the hexes don't exist outside of runtime?
    Last edited: Dec 17, 2013