Search Unity

Grids Pro: A library for hex, tri, polar and rect grids [New Dcoumentation for Grids 2]

Discussion in 'Assets and Asset Store' started by Herman-Tulleken, Jul 10, 2013.

  1. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    I have an example, but we must have forgotten to post it! We will get it up in the next hour or so.
     
  2. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    We made an example for this, which you can check out here:

    http://gamelogic.co.za/grids/examples/field-of-view-example/

    Let me know if this is what you need.

    FieldOfViewHeader.png
     
  3. BlankMauser

    BlankMauser

    Joined:
    Dec 10, 2013
    Posts:
    138
    Does this support non-uniform grids? Also how about wrapping a grid around a 3D object? (Not necessarily perfectly, but being able to map a flat space on an object) My idea is to have movement conformed to grids, but have some cells on the grid be slope or wall grids. And if approached without enough speed you would not be able to continue on them.
     
  4. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    The answer to both questions are yes :)

    Some links and images:

    http://gamelogic.co.za/grids/featur...-a-rectangular-grid-on-the-inside-of-a-torus/

    http://gamelogic.co.za/grids/features/examples-that-ship-with-grids/tiling-a-sphere-with-hexes/

    http://gamelogic.co.za/grids/examples/grids-on-a-mobius-strip/

    http://gamelogic.co.za/stairway-to-heaven/ (Spiral)

    http://gamelogic.co.za/2013/11/29/day-29-game-29-30-games-in-30-days-using-grids/ normal_torus2.png HexSphere.png GridsOnMobiusBand.png screen_17.png screen_4.png
     
    twobob likes this.
  5. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    uGUIHeader.png
    We just uploaded the example. Let me know if this is what you need.

    http://gamelogic.co.za/grids/examples/grids-with-ugui/
     
  6. GLID3R82

    GLID3R82

    Joined:
    Aug 7, 2013
    Posts:
    10
    Grids Pro is compatible with ProBuilder??
    because the grid in bundle with Probuilder is only square........ Grids Pro could be used as a base for creating for example pentagon or hexagon skyscraper in a city of the future??
     
    Last edited: Mar 4, 2015
  7. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    I am not familiar with the tech in ProBuilder, so I cannot say for sure. But Grids usually work well with other libraries. And yes, if you have futuristic buildings in hex or pent grids, Grids is your friend :)

    hexmaze3.png
     
  8. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    Grids (Pro) is not an editor grid for building levels, right?
     
  9. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yup, that is true. But Grids do make it easier to build your own level editor, or add some editing extensions.
     
  10. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79
  11. murteas

    murteas

    Joined:
    Feb 14, 2012
    Posts:
    62
    I'm very interested in this, is the 30 day trial version out of date or will it give me a good feeling for what is in the final product?
     
  12. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    48
    Hello,

    First, This is an Amazing Asset.

    Second, I need to know if something is possible, im sure it is but I need assurance before I buy :)

    I am Working on a crosswords game, but cannot seem to get a technique to work, I need to draw a line with my finger on the tiles but only allow the line to snap to grid, Rect Grid, where tiles will only be activated upon the line connecting to their "X,Y" position, if you need an example, the game "Ruzzle" on Android, attahced image for reference.



    Thank you
     
  13. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    It's definitely possible. You will need to implement the input method yourself, but grids will take care of the snapping.

    Code (csharp):
    1. Vector3 snappedPosition = Map[Map[mousePosition]];
    Two calls to map is necessary - the first converts the point where the finger is at to a grid point, and the second converts it back to a world point centered in the cell.

    Most of your work will be to handle the technicalities of the drag - making sure you only do things when the grid point changes, keeping track of the path so far, deciding when to add a new point, and so on. Once you get to that stage, I an help with more detailed information.
     
  14. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    48
    Great :) Thank you

    I bought the Lite version because all I need is square Grids for now, I noticed it doesn't work with Unity 5 Yet, so im starting on 4.6.2 for now and hoping to see a Unity 5 version soon :) Thank you
     
  15. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi there.

    It is most definitely supposed to work with Unity 5. Can you please tell me what issue you are having? Hopefully it is something small. (We were also testing with the beta, so it's possible that something slipped in with the actual release. We will download it and test it again).
     
  16. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    48
    Strange, I re-imported the Asset to unity 5 and it didn't show any errors and now its working well :) before it showed that all scripts were missing, Like Grid Cells and such, maybe it was an error from my side upon importing, its all good :) thank you
     
    Herman-Tulleken likes this.
  17. barjed

    barjed

    Joined:
    May 9, 2013
    Posts:
    70
    Hi Herman,

    just wanted to post a quick update. I set up a second grid, like you described and everything works perfectly. I even busted a small dance when all came together. After all this time, the solution was so elegant and simple!

    I ended up doing it as straightforward as possible. I generated a second grid, made it visible by the 3D object camera, rotated it so it aligns with the 2D grid (this was actually very simple, I used the exact same shape, and applied the same rotation the 3D camera has). Then I added another Position property to our cell's viewmodel (matching the original grid by X,Y point coords) - one that described the position of the second, rotated grid.

    Thank you very much Herman, you are a lifesaver!

    edit: Gee, I can't say how much simpler everything is now. In the past we had to calculate rotations by ourselves to simulate isometry and force drawing order by manipulating Z and other shenanigans. Now I place a character on a square and it just works.
     
    Last edited: Mar 7, 2015
  18. bigSadFace

    bigSadFace

    Joined:
    Aug 18, 2014
    Posts:
    116
    Does the current Demo work in U5? I've tried; however some of the examples have issues (alignment etc).

    Does the demo include all of the sample content and examples?
     
  19. barjed

    barjed

    Joined:
    May 9, 2013
    Posts:
    70
    Here's my setup, if anyone is wondering.



    White grid is the reference 3D grid, invisible in game, used to position the characters for 3D object camera. The only thing slightly annoying to resolve is finding if it's possible to somehow put all the characters on a single plane, while maintaining this setup. This would be nice for shadow casting and collisions.
     
    Herman-Tulleken likes this.
  20. DanW

    DanW

    Joined:
    Nov 4, 2013
    Posts:
    7
    I'm trying wrap my head around using FlatHexPoint.IsInNegativeHalfPlaneZ
    I want to find all the points on the bottom part of my grid as shown in this pic... http://1drv.ms/1x83tLf
    How would I return just those points? I saw a post of yours on a gamedev site but all the equations were missing (something to do with latex).

    At any rate, any advice other than searching the entire grid and comparing neighbors? There seems to be a lot of power in halfplanes and I just want to understand them.

    Thanks!
    Dan
     

    Attached Files:

  21. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    Grid and unity terrain (again?)

    I tried to map a grid over an unity terrain and found an earlier post about that. Sadly the result is not what i expected as the grid is oriented to the Y axis and doesn't cover the terrain.


    What am i doing wrong and Is there somewhere a tutorial about that ?

    Thanks


    Code (CSharp):
    1.  
    2. grid = PointyHexGrid<SpriteCell>.FatRectangle(ColumnCount, rowCount);
    3.             map = new PointyHexMap(new Vector2(cellWidth, cellHeight))
    4.                         .WithWindow(newRect(0, 0, terrain.terrainData.heightmapWidth, terrain.terrainData.heightmapHeight))
    5.                         .AlignMiddleCenter(grid)
    6.                         .To3DXY();
    7.  
    8.             foreach ( PointyHexPoint [B]point[/B] in grid) {
    9.                 SpriteCell cell = Instantiate(cellPrefab);
    10.                 Vector3 worldpoint = map[[B]point[/B]];
    11.                 cell.transform.parent = root.transform;
    12.                 cell.transform.localScale = Vector3.one;
    13.                 cell.transform.localPosition = worldpoint;
    14.                 cell.name = [B]point[/B].ToString();
    15.                 grid[[B]point[/B]] = cell;
    16.             }
    screenshot: https://www.dropbox.com/s/o8qfyt0va6c5w92/grid.jpg?dl=0
     
  22. MayhemMike

    MayhemMike

    Joined:
    Oct 23, 2013
    Posts:
    51
    It is a great asset but man it really needs a better beginner friendly documentation.
     
  23. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    In the last line of the map creation code, you will see a conversion To3DXY. All you need to do is replace that with To3DXZ (and make sure your prefabs are oriented the right way - Grids doesn't do that). Let me know if that does the trick.
     
  24. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Glad it's working now :)
     
  25. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    The demo is supposed to work in Unity 5, but I will double check that today. It does include all the content yes, although in general it may be slightly out of date. The main restriction is that you cannot make builds, and there is of course the watermark.
     
  26. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    The demo is working under U5... and facepalm for not thinking to modify the Y axis...
     
  27. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    The built-in halfplane methods only works on axis-aligned halfplanes. Just to be clear, the X, Y and Z axes of grids are different from Unity's X Y and Z axes.

    Here is the image:

    screen_406.png

    X is the red, Y is the green, and Z is the blue. The Z axis is a redundant axis, and is provided because it makes equations sometimes neater. The Z coordinate is simply -X - Y. (After some time working with these equations, I came to realize that practically it's easier just to forget about the Z axis completely.)

    The half-plane you are looking for is described by this equation:

    X + 2Y >= 0

    I do not have other advice for working with half-planes than iterating through them. Do you have efficiency concerns? How big will your grid be? The FOV example we provide is still quite snappy on a 100x100 grid (~10 000 hexes) but thre is a slight delay on a 200x200 grid (~40 000 hexes). This assumes if course discrete updates. If you either need to make continuous updates, or work on grids large enough that it matters, then you will need to devise an optimization strategy. Depending on what exactly you need, a scheme by which you limit the set of total points being evaluated (possibly by maintaining a "window" container that gets updated as the point of interest moves) will probably work well. It should also be possible to manipulate the spiral iteration to get a faster lookup (but this is a bit speculative).

    Is this enough? If you can provide more information about what you need, I can give more specific advice.

    (Thanks for pointing out the issue on the other gamedev site. Looks like the math plugin broke after an update; will check it out).
     

    Attached Files:

  28. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Thanks for the feedback! Is there anything specific you think we should cover? It's always hard for us to understand what others do not know (especially after working with the library for almost two years now). Any feedback will be greatly appreciated!
     
  29. sacha

    sacha

    Joined:
    Oct 29, 2012
    Posts:
    22
    I would go for something like:
    • Mapping a Terrain or Mesh
    • Converting a Transform into a cell position (Am i on a cell and if yes which one)
    • Assuming the grid itself is needed for showing only, displaying x grids around a 3d coordinate (if it make sense).
    S.
     
    Herman-Tulleken likes this.
  30. MayhemMike

    MayhemMike

    Joined:
    Oct 23, 2013
    Posts:
    51
    It's difficult to point into the right direction. A lot of times things seemed very confusing at first and it took me ages to figure it out but once I got it it was embarrassingly simple. But in hindsight I guess a small example with a 2x2 grid that shows you how you get from a point to a cell and access other grid features from that point onward, nothing big and fancy, just to show the different types, concepts and classes working with each other would have made it a lot easier to get the bigger picture.
     
    Herman-Tulleken likes this.
  31. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    Hey,
    i bought your asset (Grid Pro) and wanted to know if there was a little tutorial
    to start to understand the relation between all class and how to use the Editor class!

    Sorry if i'm asking for something too big.
    it's my first Asset that i want to learn to use !!
    It seems to do almost all the thing i need or all the thing i need to make a Tactic RPG!

    But i dont really understand how and where to start ! :p

    if someone could help me or point me to some video / documentation for learning Grid Pro!

    thx in advance!

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    I've found the documentation but is there any exemple for a basic character deplacement in grid style Tactic RPG !? :D

    if not i will continue to follow the documentation and try to make my own but if there is an exemple... it could bootstrap my project!
     
    Last edited: Mar 11, 2015
  32. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
  33. lend

    lend

    Joined:
    Aug 7, 2014
    Posts:
    13
    2DToolkitGridsDemo has error.
    http://gamelogic.co.za/example-with-2d-toolkit/

    Assets/2DToolkitGridsDemo/RectTest_2dtk.cs(10,30): error CS0246: The type or namespace name `GLMonoBehaviour' could not be found. Are you missing a using directive or an assembly reference?

    Probably,it needs

    using Gamelogic;

     
  34. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Thanks for spotting that! That should indeed be the fix. We will upload a new example.
     
  35. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hi there,

    Did you also find the videos?

    As it happens, we don't seem to have an example of a character soothly moving from cell to cell. The logic is pretty much the same as moving blocks from cell to cell, so you can check out this example. It's a match-game, but the code that smoothly takes an object from cell to cell should be exactly the same as for an RPG. Look at the logic of that code, and see if it makes sense to you to apply that to character movement. Let me know if you jave more questions!
     
    Last edited: Mar 17, 2015
  36. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    I found 2 video "how to make a grid in the editor" and the "lightout grid in 20min"

    the second video made me understand the basic i think...

    Can you tell me what's the example you are talking about ?
    it will help me a bit more because i need to fix 10-50 errors per example in unity 5 and sometime i can't fix them :(

    my real problem now is how to print my own sprite on the cell!?
     
  37. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    I found how to generate my grid with my logic for the cell.
    the first minimal step is done!

    Now i need to check how can i draw my character and move it from 1 tile to another with the A* algorithm.

    I have Wall tile and floor cell to start up.

    And i need to find out how to create the grid from code! - Found it - Done

    My main probleme is to know the limit of my grid. Is there a function that give me if the tile is the limit. the method GetEdges of tile is giving out of grid tile so ... i dont know how to find them!
     
    Last edited: Mar 15, 2015
  38. anpd03

    anpd03

    Joined:
    Aug 7, 2013
    Posts:
    65
    Hi, I have some different map generators that build random maps in a 2d array. I want to add the values from the array to a pointy hexgrid, is there a way to iterate through a grid from top left to bottom right to place the values in the same way they are in the array?
     
  39. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    If you can tell me the example your talking about the match-game it could be very usefull.

    Is it possible too to tell me if there is a way to know the Cell that are at the limit of the grid!
    I didn't find a good way to do it.. (i'm using FlatHexPoint in a FlatRect

    the size will be dynamique so i need to easily know if a cell is at the limit of the grid!
     
    Last edited: Mar 17, 2015
  40. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Sorry I forgot to add the link!

    Here it is:

    http://gamelogic.co.za/2014/05/10/match-game-mechanics/

    To change the sprite, simply change the sprite of the cell prefab that you have in the grid (the prefab that you drag into the grid builder).
     
  41. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You can change the iteration order by sorting the points. Something like:

    Code (csharp):
    1. var orderedPoints = Grid.OrderBy(p => p.X).ThenBy(q => q.Y);
    (You may need to swap the X and Y or use OrderByDescending or ThenByDescending depending on your exact layout).

    If you don't care about the layout of the array, you don't have to worry about the exact order of the points, except that iteration will be consistently in the same order (as it is). You can then read in and out of a grid using the default iteration.

    Code (csharp):
    1. var valuesAsArray = Grid.Values.ToArray();
    2.  
    3. int i = 0;
    4. foreach(var point in Grid)
    5. {
    6.    Grid[point] = valuesAsArray[i]; //read back into the same cell
    7. }
    The code above will leave the grid intact. (Totally useless, just to make the point).
     
    apgames likes this.
  42. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    You can use the following to see if a cell at a grid point is on the border of the grid:

    Code (csharp):
    1. bool isBorderPoint = Grid.GetNeighbors[gridPoint].Count() < 6;
     
  43. apgames

    apgames

    Joined:
    Nov 19, 2013
    Posts:
    6
    Thanks, works great :)
     
  44. Korigoth

    Korigoth

    Joined:
    Jul 21, 2014
    Posts:
    105
    Thx a lot i was searching on the gridPoint methods ... but the GetEdges was not the good answer :p

    Do you remember the example you were talking about ?
    If you can point me out a little bit to know which one is it... cause i'm not sure if i found the good example

    I found an example that you place a point if it match 3 then no more color is added and you remove the match else the game add some color point in the game

    is it the example you were talking about?
     
  45. apgames

    apgames

    Joined:
    Nov 19, 2013
    Posts:
    6
  46. Culzean

    Culzean

    Joined:
    Jan 25, 2014
    Posts:
    48
    Hello!

    First can I say the feedback here has been great! Really appreciate the responsiveness here.
    I have a question about path finding here. A very basic example where I have the AStar search set up as basic as possible with a PointyHexPoint grid. But the path returns a hex that is off of the grid! This surprises me.
    path1.jpg

    Do I have to supply an IsAccessible function? I did not suppose this was required to check for valid neighbours. Is there something I have done wrong is setting this grid up?

    Thanks
     

    Attached Files:

  47. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    This is surprising. You are not supposed to have to check for neighbors. Could you please email me a package herman@gamelogic.co.za so that I can have a look?
     
    Culzean likes this.
  48. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Sorry the link got left out in my original post. Here it is again (it is the example you talk of). Does this help you?

    http://gamelogic.co.za/2014/05/10/match-game-mechanics/
     
    Last edited: Mar 19, 2015
  49. apgames

    apgames

    Joined:
    Nov 19, 2013
    Posts:
    6
    I do, thanks will take a look at that.
     
  50. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    We do not have an example, but it's a good idea for one.

    Doing it is slightly tricky. Here are the basic steps of one way to do it:

    First notice that the border is made from circular arcs with centers that coincide with hex centers, and drawn between two points that lie on the centers of the hex edges. This algorithm finds the three points so that you can draw an arc:

    edge.jpg

    1. Make an edge grid (using GetEdgeGrid) and a map for it. The edge grid is a RhombGrid. Centers of these rhombs coincide with the centers of edges of the hex grid. See this example http://gamelogic.co.za/grids/exampl...-for-faces-vertices-and-edges-simultaneously/ to see how the concept works. (Note that you may need to play around with the map a bit to make it align properly).
    2. Now, for the region that you want to draw the border for, get the associated edges, using GetEdges on each point in the region. Something like
      Code (csharp):
      1. var edges = region.SelectMany(p => p.GetEdges());
    3. Remove duplicates from the list.
    4. Filter the list to get the borders only, the same way I described for hexes before, but using 4 neighbors.
    5. Now sort the rhombs in a path. Start by adding any one (the first, say) to a new list. Then add one of it's neighbors. Then add the new rhomb's neighbor that is not already added, and so on, until you have added them all.
    6. Now iterate through the sorted list of edges. For each one, also take the next one. These two rhombs have centers at the start and finish points of the arc (use the edge map you created in step 1 to get the world coordinates of this). They also share a common hex face in the original grid. The center of the hex is the center of the arc. This should now be enough information to actually draw the arc.
    Notice, from the image, that in principle a tile-based solution is also possible (where you have arcs drawn in rhomb tiles). The tile will can be flipped two ways, so you will need a criterion to decide which way to flip it. The criteria will (I think) be different for the 3 different indices of the rhomb point, and will be whether the shared hex face is inside or outside the region.

    I realise that this is a lot to take in. I would suggest first familiarizing yourself with the concepts of vertex and edge grids, and understand how rhomb grids work. (Check out the grid index http://gamelogic.co.za/grids/documentation-contents/quick-start-tutorial/grid-index/ to understand the coordinate system.) Also, use the edge grid during development to make sure each step is correct. For example, make the tiles of the border edges a different color in step 4.

    screen_411.png
     
    Last edited: Mar 19, 2015
    Culzean and apgames like this.