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
    Interesting... there are a few things that may be going on. My guess is that the grid cells and arch are parented to different roots, and these roots have different transforms. Therefore, the mapping gives incorrect results.

    If this is the case, you could root the other objects to an empty game object with exactly the same transforms (which may mean you may need to change the scale and local position of these objects). Alternatively, you could apply the grid root's transform to the position before you do the mapping.

    Does this make sense? (If you want, you can export me a package to have a look at it: herman@gamelogic.co.za).
     
  2. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    var hexPoint = Map[worldPosition];
    ...........
    public TPoint this[Vector3 point]
    {
    get
    {
    var point2D = new Vector2(point.x, point.z);

    return map2D[point2D];
    }
    }

    So like above code, when grid recognize mouse's position, it only takes its x and z coordinate.

    This is why above phenomenon occured.

    Of course I don't mean this is wrong. That arch object will not be so high above from ground, and from gamer's experience view, when he touch arch, its ground selected can make sense.
     
    Last edited: Dec 26, 2014
  3. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Have another question.

    I use A* pathfinding algorithm to finding ways,

    but now I want to know if there exist method you already made for,

    [when some character has some moving power (like int variable 1, 2, 3, ~), I want to express cell's range that character can reach at this turn with some moving power int variable]

    Thanks.
     
  4. LittleRockGames

    LittleRockGames

    Joined:
    Jan 7, 2015
    Posts:
    16
    Hi Herman,

    I'm trying out the free trial of grids and getting ready to buy. I think it's going to be a great choice for my project.

    I've been working with a flat hex grid built in the editor, and I have a question. The grid is a rectangle made of 3D hex blocks. If I delete a cell from the center of that grid to put something else there (in this case, the cell's index is 8, 3), what are the consequences of that for the grid's logic? Are there any unexpected issues that would arise? If so, would it be better to create a custom grid in code which has a gap at the center?

    Thanks for any help you can offer!
     
  5. barjed

    barjed

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

    I am having a issue with some reasoning around Grids and I was hoping you could help a bit.

    My grid (diamond, faux isometry) is a 2D object, based on a XY plane, with a Ortho camera looking directly at it.

    I have another ortho camera which sees only 3d models of objects that are supposed to move around the grid, but the that camera is rotated (30,45,0) in order to achieve an isometric perspective for the models.

    The issue here is that because the coordinate systems of the two cameras are no parallel to each other, the 3D model on screen position do not match it's supposed position on a grid.

    Is there any way around this?

    Thanks!
     
  6. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    We just introduced this feature in Grids 1.10, which the Asset store accepted Friday evening (evening were we are). We will add a tutorial later this week after our official announcement, but you can check the functions out in the meantime:

    http://gamelogic.co.za/documentatio...rithms.html#ad3fd9c6bfe20bd7cd9f0c84682334d0a

    http://gamelogic.co.za/documentatio...rithms.html#a7c7aabce61e6b1c51b447dc367d95b15

    That last function returns a dictionary with all points that can be reach as keys, and the cost to reach them as values.
     
  7. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Doing it that way can cause some problems (it may lead to null pointer exceptions when you run some of the algorithms, for example). Your hole may also be destroyed when the grid is rebuilt.

    There are a few ways you can deal with this. The simplest way would probably be to add a GridBehaviour to the grid component, and simply replace the relevant cell in the InitGrid method. Soomething like this:

    Code (csharp):
    1. public GridWithHoleGridBahaviour : GridBehaviour<FlatHexPoint>
    2. {
    3.    public Block holePrefab;
    4.  
    5.    override public void InitGrid()
    6.    {
    7.         var holePosition = new FlatHexPoint(8, 3);
    8.         Destroy(Grid[holePosition].gameObject);
    9.        
    10.         var holeInstance = Instantiate(holePrefab);
    11.         holeInstance.transform.parent = transform;
    12.         holeInstance.transform.localScale = Vector.one;
    13.         holeInstance.transform.localPosition = Map[holePosition];
    14.         Grid[holePosition] = holeIstance;
    15.    }
    16. }
    If you want algorithms to treat this cell differently, you may want to define your own cell that derrives from Block, and introduce some logic that will make (and mark) a cell empty. Something like this:

    Code (csharp):
    1. class MyBlock :  Block
    2. {
    3.    private bool empty = false;
    4.    public bool Empty
    5.    {
    6.       get { return empty; }
    7.       set
    8.       {
    9.           empty = value;
    10.           UpdatePresentation(); //A method to do the object switch
    11.       }
    12.    }
    13. }
    Then you can use this in your grid behaviour:

    Code (csharp):
    1. public GridWithHoleGridBahaviour : GridBehaviour<FlatHexPoint>
    2. {
    3.    public Block holePrefab;
    4.  
    5.    override public void InitGrid()
    6.    {
    7.         var holePosition = new FlatHexPoint(8, 3);
    8.         Grid[holePosition].Empty = true;
    9.    }
    10. }
    And when you use an algorithm such as AStar, you can use this property to control behaviour:


    Code (csharp):
    1.  
    2. var path=Algorithms.AStar(
    3.   grid,
    4.   start,
    5.   goal,
    6.   (p,q)=>p.DistanceFrom(q),
    7.   c=>!c.Empty,
    8.   (p,q)=>1);
    9. //This will only find paths over non-empty squares
    There is a third option, and that is to define your own grid shape with the hole in it.

    http://gamelogic.co.za/grids/docume...k-start-tutorial/making-your-own-grid-shapes/

    However, it is a bit tricky, and probably overkill for this simple scenario.
     
    LittleRockGames likes this.
  8. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    For 3D you have to use a raycasting method to get object coordinates, and use that in the map:

    Code (csharp):
    1.  
    2. public void Update()
    3. {
    4.    if (Input.GetMouseButtonDown(0))
    5.    {
    6.       var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    7.  
    8.       RaycastHit hit;
    9.  
    10.       if (Physics.Raycast(ray, out hit))
    11.       {
    12.          Vector3 worldPosition = gridRoot.transform.InverseTransformPoint(hit.point);
    13.          Debug.Log("mouse pos: " + Input.mousePosition + ", world_pos:" + worldPosition);
    14.  
    15.          var hexPoint = Map[worldPosition];
    16.  
    17.          if (Grid.Contains(hexPoint))
    18.          {
    19.             Debug.Log("Grid hit: " + hexPoint);
    20.          }
    21.       }
    22.    }
    23. }
    You may want to filter some layers, and remember that your objects should have colliders on them for this to work.
     
    Kivak likes this.
  9. Leandro_Gado

    Leandro_Gado

    Joined:
    Sep 29, 2013
    Posts:
    14
    Could Grids be used with cells with a random number of neighbours, like a world map or a voronoi diagram?
     
  10. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    Hi,

    I'm trying to use Diamond Grids on iOS and I got following compiler error:

    Code (CSharp):
    1. ExecutionEngineException: Attempting to JIT compile method 'Gamelogic.Grids.AbstractUniformGrid`2<Gamelogic.Grids.TileCell, Gamelogic.Grids.DiamondPoint>:.ctor (int,int,System.Func`2<Gamelogic.Grids.DiamondPoint, bool>,System.Func`2<Gamelogic.Grids.DiamondPoint, Gamelogic.Grids.DiamondPoint>,System.Func`2<Gamelogic.Grids.DiamondPoint, Gamelogic.Grids.DiamondPoint>)' while running with --aot-only.
    2.  
    3.   at Gamelogic.Grids.DiamondGrid`1[Gamelogic.Grids.TileCell]..ctor (Int32 width, Int32 height, System.Func`2 isInside, System.Func`2 gridPointTransform, System.Func`2 inverseGridPointTransform) [0x00000] in <filename unknown>:0
    4.   at Gamelogic.Grids.DiamondGrid`1[Gamelogic.Grids.TileCell]..ctor (Int32 width, Int32 height, System.Func`2 isInside, DiamondPoint offset) [0x00000] in <filename unknown>:0
    5.   at Gamelogic.Grids.DiamondShapeInfo`1[Gamelogic.Grids.TileCell].MakeShape (Int32 x, Int32 y, System.Func`2 isInside, DiamondPoint offset) [0x00000] in <filename unknown>:0
    6.   at Gamelogic.Grids.AbstractShapeInfo`5[Gamelogic.Grids.DiamondShapeInfo`1[Gamelogic.Grids.TileCell],Gamelogic.Grids.DiamondGrid`1[Gamelogic.Grids.TileCell],Gamelogic.Grids.DiamondPoint,Gamelogic.Grids.DiamondPoint,Gamelogic.Grids.DiamondOp`1[Gamelogic.Grids.TileCell]].EndShape () [0x00000] in <filename unknown>:0
    7.   at Gamelogic.Grids.DiamondGrid`1[Gamelogic.Grids.TileCell].Parallelogram (Int32 width, Int32 height) [0x00000] in <filename unknown>:0
    8.   at Gamelogic.Grids.DiamondTileGridBuilder.InitGrid () [0x00000] in <filename unknown>:0
    9.   at Gamelogic.Grids.TileGridBuilder`1[Gamelogic.Grids.DiamondPoint].Start () [0x00000] in <filename unknown>:0
    I tried to write some complier hint as you advised before, but without much luck.

    Any ideas how could I work around this?

    Thanks.
     
  11. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hey, do you mind pasting the hint you are using? If it's the hint that constructs a grid with array of TileCell, you need just make it into a non-array hint. (I can do it for you when I see what we have).
     
  12. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yup :)

    http://gamelogic.co.za/2013/11/29/day-29-game-29-30-games-in-30-days-using-grids/

    This is Lights Out on a Voronoi diagram. The actual neighbor setup is very crude (at the beginning of the game a lookup table is constructed with some brute-force technique), but once done, your irregular grid works like any other.


    GameImage_680x340_29.png

    If you want more details on how to do this, let me know.
     
  13. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79


    Grids 1.10 is now out!

    This is mostly a maintenance update, where we made many fixes and small improvements to the API interface, but there are also a few new features:
    • Range finding
    • Cells for grid builders so that they can be used with Unity’s new GUI
    • Line drawing algorithms
    • An AOT-safe stack for points
    Check out the full list of what’s new in Grids 1.10.

    In this update, we’ve also changed the structure of our packages.
    • Grids is now called Grids Pro. There are no changes other than the name.
    • Hex Grids has been changed to Grids Basic (now 50 U$D).It includes all the functionality of Hex Grids and Rect Grids. All Hex Grid users will automatically be upgraded to Grids Basic through the update.
    • Rect Grids is now called Grids Lite. It will also remain the same as before.
    This week we’ll be releasing short blog posts explaining some of the new features in a bit more detail, together with some awesome tutorials. So be sure to check out our blog or follow us on twitter to stay updated.
     
    c-Row likes this.
  14. piotrO

    piotrO

    Joined:
    Dec 16, 2009
    Posts:
    46
    Thanks for a prompt reply.

    These are the hints I was using:

    Code (CSharp):
    1.      
    2. DiamondGrid<TileCell> dg = DiamondGrid<TileCell>.Parallelogram(5,5);
    3. DiamondGrid<TileCell> dg2 = new DiamondGrid<TileCell>(5,5);
    4. DiamondGrid<TileCell> dg3 = DiamondGrid<TileCell>.BeginShape().Parallelogram(5, 5)    .EndShape();
    5.  


    Thanks,
    Piotr
     
  15. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Hi.
    So what I want is make map like Civilization 5.

    It require static map designed before, and also require generate random map.

    Have questions related to above subject.


    1. Do grids already have code that let maker register some prefabs of cell(3~10), then make map randomly from those prefabs?

    2. If grids don't have above function yet, how can I make random map? any tips?
    (I want regular random like minecraft map (beside sea tile, sand tile exist). Rather than absolute, chaotic random map.)

    Thanks.
     
  16. hatuf

    hatuf

    Joined:
    Jan 6, 2013
    Posts:
    8
    I ran into a problem with the wrapped rectangle map. I have just a little bit of code in at the moment as I was mostly basing it on the examples.
    For some reason accessing the grid like this:
    Grid[point] - gives the wrong tile. Not the one under the mouse. However getting the neighbors of that tile will return the neighbors around the mouse cursor!
    The same problem happens if I enable IsInteractive on the grid.

    If I create a Grid with Rectangle() instead of HorizontallyWrappedRectangle, it works correctly.

    Any idea why this is happening?

    Code (CSharp):
    1.  
    2. // Creating the wrapped rectangle in builder
    3. base.Grid = PointyHexGrid<TileCell>.HorizontallyWrappedRectangle(rectDimensions.X, rectDimensions.Y);
    4.  
    5. .....
    6.  
    7.  
    8. // Mouse handler
    9.  
    10. public void Update()
    11. {
    12.         if (Input.GetMouseButtonDown(0))
    13.         {
    14.             Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(gameObject, Input.mousePosition);
    15.             PointyHexPoint point = Map[worldPosition];
    16.        
    17.             if (Grid.Contains(point))
    18.             {
    19.                 // This tile is wrong
    20.                 Grid[point].Color = Color.white;
    21.  
    22.                 // The neighbors are correct
    23.                 var neighbors = Grid.GetNeighbors(point);
    24.                 foreach (var neighbor in neighbors)
    25.                 {
    26.                     Grid[neighbor].Color = Color.red;
    27.                 }
    28.             }
    29.         }
    30. }
    Changing the color of a tile with Grid[point]

    Changing the color of a tile with Grid[point]


    (The tiles it selects seem to go along the axis if that helps)

    Changing the color of a tile with Grid[point] and neighbors
     
    Last edited: Jan 13, 2015
  17. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hey Piotr, try this hint instead:

    Code (csharp):
    1. public bool __CompilerHint__Diamond__TileCell()
    2. {
    3.    var grid = new DiamondGrid<TileCell>(1, 1);
    4.  
    5.    foreach (var point in grid) { grid[point] = cellPrefab; }
    6.  
    7.    var shapeStorageInfo = new ShapeStorageInfo<DiamondPoint>(new IntRect(), p => true);
    8.    var shapeInfo = new DiamondShapeInfo<TileCell>(shapeStorageInfo);
    9.  
    10.    return grid[grid.First()] != null || shapeInfo.Translate(DiamondPoint.Zero) != null;
    11. }
    That shoukd do the trick. Let me know if it doesn't!
     
  18. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Not out of the box, but it is really easy to do. This example does exactly that:

    http://gamelogic.co.za/grids/exampl...using-scriptable-objects-to-manage-tile-sets/

    Let me know if this is what you need.
     
    OnePxl likes this.
  19. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Wrapped grids are tricky...and it seems you found a bug.

    I have patched it; we will submit an update, but in the meantime, here are the files (you can just overwrite your copies of these two files).
     

    Attached Files:

    hatuf likes this.
  20. LittleRockGames

    LittleRockGames

    Joined:
    Jan 7, 2015
    Posts:
    16
    Thanks so much for the helpful info, and for providing such excellent support for your product!
     
  21. krissebesta

    krissebesta

    Joined:
    Oct 20, 2010
    Posts:
    16
    Hey Gamelogic guys,

    Back in Oct 2010 I asked if...

    Can Grids support "layered" grids? Like 3D Tic-Tac-Toe with three layers of 9 cells? I'm planning a game with three layers (much more complex than 3D Tic-Tac-Toe however! ;-)

    Have you guys implemented an easy way of handling this?

    Cheers! - Kris
     
  22. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    I see you've changed the packages on the asset store to Lite, Basic, and Pro. The descriptions aren't clear if source is included or not. Is source included in all packages?
     
  23. hatuf

    hatuf

    Joined:
    Jan 6, 2013
    Posts:
    8
    Excellent! That fixed it. Yeah they are tricky, I saw the [Experimental] tag in there :)
     
  24. LittleRockGames

    LittleRockGames

    Joined:
    Jan 7, 2015
    Posts:
    16
    Herman,

    Can you explain this raycast idiom you posted in a bit more detail? Specifically, if I use the editor to build a grid, do I attach this script to the root (empty) object which has the grid builder component attached to it? If so, how do I reference Map and Grid so the script knows they come from the grid builder? Thanks for your help!

    Code (CSharp):
    1. public void Update()
    2. {
    3.    if (Input.GetMouseButtonDown(0))
    4.    {
    5.       var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    6.       RaycastHit hit;
    7.  
    8.       if (Physics.Raycast(ray, out hit))
    9.       {
    10.          Vector3 worldPosition = gridRoot.transform.InverseTransformPoint(hit.point);
    11.          Debug.Log("mouse pos: " + Input.mousePosition + ", world_pos:" + worldPosition);
    12.  
    13.          var hexPoint = Map[worldPosition];
    14.  
    15.          if (Grid.Contains(hexPoint))
    16.          {
    17.             Debug.Log("Grid hit: " + hexPoint);
    18.          }
    19.       }
    20.    }
    21. }
     
    Last edited: Jan 19, 2015
  25. Jonathan-Bailey

    Jonathan-Bailey

    Joined:
    Aug 12, 2013
    Posts:
    79
    All three packages include the source code. Thanks for the headsup, we've changed the initial post :)
     
  26. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    We did :)

    It's called Layered Grids. There is an example that ships with the product, and a path finding example here:

    http://gamelogic.co.za/2014/05/24/a-new-look-at-layered-grids-setting-up-neighbors/

    (Neighbors are also now easier to configure than it was by the time e made that example - now you can configure them by simply setting a variable NeighborDirections).
     
  27. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    The main point here is that (since you built your grid as an editor grid), the code would be placed in a grid behaviour attached to the same game object as the builder. The map and grid properties of the GridBehviour automatically point to the map and grid of the grid builder attached like that.

    (Note that since the grid root is automatically the current game object, you can simply say transform instead of gridRoot.transform, and you do not need the gridRoot variable).

    Here is some more information on GridBuilders:

    http://gamelogic.co.za/grids/docume...k-start-tutorial/working-with-gridbehaviours/
     
    Kivak likes this.
  28. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140
    Herman,

    I bought Grids a couple days ago and I just love it! Great product! :)

    I do have a question about custom grid cells. I would like to use a prefab which originates from an animated mesh exported from blender. When the mesh is animated it repositions itself at 0,0,0. This is a known issue normally solved by making the animated mesh a child of a container and position the container rather than the mesh (thus repositioning at 0,0,0 of the parent isn't a problem). However! The Grid script indicates that it needs to be attached to the mesh - which isn't possible...

    Have you made any 3D animated grid cells? Do you have a solution for this?

    Thanks!
     
  29. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There is definitely a solution :)

    I do need to understand your setup a bit better though. (For example, what are you basing your own cells on, are you in 2D or 3D?)

    The simplest solution is possibly to extend your own cells from TileCell, and just implement all the required methods They should all be one-liners; you can look at the implementation of SpriteCell and MeshCell for implementation hints, but it should be very easy. You can then control precisely how to access the actual mesh to implement these methods - and making it a child of another GameObject should then be possible.

    The final setup should be something like this:

    GridRoot (with the grid script or grid builder attached)
    ...CellRoot (with your own cell component attached)
    ......AnimatedMesh (the mesh you import from blender)

    The actual cell prefab like this:


    CellRoot (with your own cell component attached)
    ...AnimatedMesh (the mesh you import from blender)

    If you use a grid builder, the cell prefab should just work (so you don't have to worry about parenting beyond making the prefab). If you construct your grid in code, you simply root your instances to the grid root as you would normally do.

    Let me know if this makes sense; or please give me more details about your setup. (If all else fails you can always email me a test package and I can have a quick look to do the setup).
     
    Last edited: Jan 20, 2015
  30. Kivak

    Kivak

    Joined:
    Jul 13, 2013
    Posts:
    140
    Fantastic! I see that Block is an extension of TileCell as well. That makes life really simple. I knew you had a good solution! Thanks so much! :)
     
  31. LittleRockGames

    LittleRockGames

    Joined:
    Jan 7, 2015
    Posts:
    16
    Perfect. It worked like a charm. The piece I was missing was to derive my class from GridBehaviour<FlatHexPoint>. Thanks!
     
  32. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Hello Herman

    What process would you recommend for having an AI deal with Grids in a boardgame scenario? Can I simply create a copy of an already existing grid in memory and use that for calculations?


    : edit : Bonus Question :D Isn't there a way to get this to work through the magic of Linq without a foreach loop?

    Code (csharp):
    1. PointList<RectPoint> startingPoints = newPointList<RectPoint>();
    2. foreach (RectPoint point in actualGrid)
    3. {
    4.    if (actualGrid[point].walkable == true)
    5.    {
    6.       startingPoints.Add(point);
    7.    }
    8. }
     
    Last edited: Jan 22, 2015
  33. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yup :)

    There is a method CloneStructure; which makes a copy of the grid in a new type. It can also take a some parameters to initialize the initial elements.

    http://gamelogic.co.za/documentatio...t_01_4.html#a1056f046a546dc23c65887d15130929b

    And this is often a good way do work. An alternative way is to make slightly smarter cells, but IMHO that is less flexible. (It also depends on how much your presentation depend on the logical state. If the presentation is highly dependent, it may be easier to use the second approach.)

    The code you posted above can be written as:

    Code (csharp):
    1. var startingPoints = actualGrid.Where(p => actualGrid[p].walkable);
     
  34. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    I knew your Linq-Fu was stronger than mine. :D

    One thing I noticed is that a function I wrote which tries to find and return a suitable PointyHexPoint for the next move won't let me return null as a result if there is none for whatever reason since apparently a PHPoint can never be null. Any idea how to get around that issue?
     
  35. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Grid points, like Vector3 and such types, are structs and hence cannot be null. The vanilla way to get around this is to use a nullable type*, for example

    Code (csharp):
    1. public PointyHexPoint? FindAPoint()
    2. {
    3.    PointyHexPoint? point = null;
    4.  
    5.    if(/*found*/) point = foundPoint;
    6.  
    7.    return point;
    8. }
    9.  
    10. //And in your code
    11. ....
    12.  
    13. var point = FindAPoint();
    14.  
    15. if(point.HasValue) ...
    16. else ...
    *Note: the ?? operator gives unpredictable results on Unity types (such as mono behaviours) and therefor I avoid using it altogether.
     
    c-Row likes this.
  36. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    Ah, I see. Back to AI programming tonight. :)
     
  37. mellowanon

    mellowanon

    Joined:
    Nov 11, 2013
    Posts:
    2
    Hello, I'm getting errors even with an empty projects.

    Loading a new project with just the following:
    Grids Basic
    Gamelogic Extensions.unitypackage
    2D setup defaults

    it give the error "Assets/Gamelogic/Plugins/Grids/GridTypes/Diamond/DiamondGrid.cs(118,51): error CS1061: Type 'System.collections.Generic.IEnumerable<Gamelogic.Grids.DiamondPoint>' does not coctain a definition for 'TakeHalf' and no extension method 'TakeHalf' of type 'System.collections.Generic.IEnumerable<Gamelogic.Grids.DiamondPoint> could be found (are you missing a using directive or an assembly reference?)
     
  38. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Grids Basic comes with a (slightly newer) version of Extensions, so if you include Extensions separately as well, that method does not exist. You can fix it by simply deleting the extensions folder, and re-import Grids Basic. (We will update Extensions soon too).
     
  39. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    How do you translate world coordinates to grid coordinates using a grid built via the editor?

    I have a PointyHexTile grid created using the PointyHexTile Grid Builder in the editor. I have a script attached to the grid that extends GridBehaviour.

    I expected Map[cell.transform.position] to give me the point coordinates of a cell, but it doesn't. For example:

    HexTileCell cell = (HexTileCell)Grid[point];
    Debug.Log(cell + " is at " + Map[cell.transform.position]);

    I expected it to report that cell (0,0) was at 0,0, but instead its says that it's -6,4.

    My specific goal is to get the neighbors of a cell, but I'd like to understand how to translate world coordinates to grid coordinates and vice versa using a grid constructed in the editor.
     
  40. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,476
    Are there any method of lower drawcall for grids system?

    So when I load default scene and zoom camera like attached distance, drawcall is over 330.
     

    Attached Files:

  41. Unib0t

    Unib0t

    Joined:
    Jan 4, 2013
    Posts:
    15
    When creating a rectangular flat hex grid, the column tops (starting from the left) are staggered low - high - low, is there a way to change this to high - low -high?
     
  42. Yebe

    Yebe

    Joined:
    Dec 23, 2014
    Posts:
    2
    Does Grids works with RTS style game where the buildings have grid placement (like Supreme Commander or Starcraft 2) but the units does not have grid movement?

    And does this works with Unity free?
     
  43. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    I think the only mistake you made is that you used position instead of localPosition. The map assumes positions relative to the grid root. Let me know if that was the issue.
     
  44. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Hmmm you should not be seeing that. It is not something with Grids, but the materials / shaders and how grids try to set them, but there should be some batching going on. I will investigate and get back to you.
     
  45. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    There are two rectangular shapes - fat and thin. The thin one is high low high, and the fat one is high low high. Let me know if this is what you need.
     
  46. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Yes, you can use Grids with non-grid like things, you could even use separate grids for different things in your game. You can also use grids without any visual presentation, such as for snapping buildings.
     
  47. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    I'm finding that the AStar performance is sub-par on large grids. I think the reason for this is that you are using a List<> as the base for openset/closedset. I've found in the past that list.indexof, list.contains and other list methods perform really poorly on large collections. You may want to consider changing these to using dictionary<> under the hood, its a lot faster for lookup operations (slightly slower for add operations).

    http://theburningmonk.com/2011/03/hashset-vs-list-vs-dictionary/

    Otherwise, loving the asset.
     
  48. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    As a test, I modified your astar to use dictionaries instead of lists. I'm generating many paths, and the only difference between these two results is using your method vs mine

    Dictionary:
    set 1:Elapsed: 00:00:00.2570705;
    set 2:Elapsed: 00:00:00.1382934;
    set 3:Elapsed: 00:00:00.1668291;

    List:
    set 1:Elapsed: 00:00:11.7942760;
    set 2:Elapsed: 00:00:04.5504785;
    set 3:Elapsed: 00:00:04.8111750;

    I don't want to post the source here, but if you want I can email you the file.
     
    Herman-Tulleken likes this.
  49. Herman-Tulleken

    Herman-Tulleken

    Joined:
    Nov 20, 2009
    Posts:
    358
    Thanks for the feedback!

    I am curious, how big are your grids (~ballpark)? I did several tests with different data structures for the Range Finding algorithm (slightly different), but only with smallish grids. It would be great if you could mail me some code; thanks for offering!
     
  50. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    That grid is a 100x100 RectGrid. It was 300x300, but I had to reduce it because the pathfinding would take over a minute in some cases. I'll PM you the two functions I had to change.

    *Edit
    Just for reference, here is an example of my grid (real early visualization of my map). The white areas are where water "can" flow. It can only flow downhill. I'm generating paths from areas designated as lakes, to the edge of the map using that water plane. The light blue paths are the generated paths. I have to keep rerunning the pathfinding algorithm until I find a path that actually reaches the edge, since not every water plane end point is reachable by the lake start points.

    level.JPG
     
    Last edited: Feb 4, 2015