Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Grid Framework [scripting and editor plugins]

Discussion in 'Assets and Asset Store' started by hiphish, Jul 24, 2012.

  1. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    43
    Hiphish,

    Thanks for fixing the Unity 5.4 data_path error.

    I just downloaded the change 2.1.1 into a project that contains GridFramework and Vectrosity 5.3. After adding GRID_FRAMEWORK_VECTROSITY to scripting define symbols in ProjectSettings > Player, I am now getting the following error for all 3 of your renderers when I try to run your Vectrosity example scene.

    IndexOutOfRangeException: Array index is out of range.
    GridFramework.Renderers.Rectangular.Parallelepiped.CountLines () (at Assets/Plugins/GridFramework/Renderers/Rectangular/Parallelepiped.cs:59)
    GridFramework.Renderers.GridRenderer.UpdatePoints () (at Assets/Plugins/GridFramework/Renderers/GridRenderer.cs:278)
    GridFramework.Renderers.GridRenderer.Awake () (at Assets/Plugins/GridFramework/Renderers/GridRenderer.cs:439)
    UnityEditor.DockArea:OnGUI()

    Your non-vectrosity example scenes seem to run fine.
     
  2. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    This is a weird one. It seems related to how Unity serialises objects: if I remove the renderer and the script and then add them back to the object it works fine, even if I didn't change a line of code. Unity must be serialising the renderer in a state where the array does not exist with the wrong size.

    This might take a while to narror down for certain, but I think making the offending member field non-serialised should do the trick. If you want to try it for yourself: In the file Plugins/GridFramework/Renderers/GridRenderer.cs delete line 86 so it looks like this:
    Code (csharp):
    1. /// <summary>
    2. ///  Amount of draw points.
    3. /// </summary>
    4. /// <remarks>
    5. /// <para>
    6. ///  Each of the three entries stands for the amount of *lines* to
    7. ///  draw per corresponding axis. You need to mutate this member in
    8. ///  <c>CountLines</c>.
    9. /// </para>
    10. /// </remarks>
    11. protected int[] _lineCount = {0, 0, 0};
     
  3. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    After some more testing it turns out that serialisation was indeed the issue. I have submitted a new version, the one-line fix will bridge you over in the meantime until it gets approved.
     
  4. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Pretty examples
     
  5. True29

    True29

    Joined:
    Jun 27, 2013
    Posts:
    20
    i cant find the help file , can you sent me the help file pls ? email is happ17 (a) web.de thx.
     
  6. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Something went wrong with the last update, a new one has been submitted and is currently waiting for approval. Here is a link in the meantime, extract the ZIP under Plugins/GridFramework/

    [Link removed, update has been published]
     
    Last edited: Mar 17, 2017
  7. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Grid Framework version 2.1.4 released
     
    wetcircuit likes this.
  8. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    202
    Hi there! I'm just wondering whether it's possible to make an isometric 2d pixel grid in the X/Y axis with your asset? You can see what I'm after with the below images:

    [​IMG]

    [​IMG]
    So I want to create essentially a diamond grid in the X/Y axis, for a 2d grid-based game. But the idea is that down the road I can add a 3d free-camera option, as the underlying game engine is decoupled from the graphics and interface. The game is a square grid, but I want to use it with diamond pixel grid sprites.

    I hope that makes sense! And was wondering whether this is possible using your asset? Additionally does your asset contain things like range finding and weighted pathfinding?

    Thanks in advance for any help!
     
  9. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Hello
    Yes, you create a "rectangular" grid and adjust the spacing and shearing values accordingly, for example to a spacing of (2, 1) and a shearing of (-0.5, 2) to get a grid like in this image:
    [​IMG]
    The term "rectangular" is a bit misleading since the grid can have sharing that makes it no longer rectangular, but that's a leftover from the early days before shearing was implemented. The grid coordinate system is still the same though, the shearing rotates the basis vectors in the world, but when scripting the grid-coordinate system is still "rectangular".

    I don't know what you mean by range finding? Do you want the distance of two positions in grid coordinates? That's simple:
    Code (csharp):
    1. Vector3 alice, bob;  // world coordinates
    2. RectGrid grid;
    3. var distance = grid.WorldToGrid(alice) - grid.WorldToGrid(bob);
    Pathfinding is not included. I was entertaining the idea for a while, but I concluded that pathfinding is too specific, there are many ways to do pathfinding, and if I picked One True Way™ it would only be useful to a subset of users and frustrating to everyone else. The guiding design principle of Grid Framework has always been to provide a library that you can adapt to your game instead of having to adapt your game to it. This means it's not a "just add water" type of kit, but at the same time it offers you freedom and flexibility a kit could not offer. I hope this makes sense as an explanation.
     
  10. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    202
    It does, and thanks for the reply! By range finding I mean 'get a list of all tiles within 3 squares', but I assume as pathfinding isn't a part of the frame work, this wouldn't be either.

    It makes perfect sense keeping it slim, but I'm after a grid solution that can handle that stuff. Thanks very much for the response!
     
  11. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    There is no "tile" data structure, because again, what a "tile" is depends on the game. You can keep an array of your own "tile" type to keep track of your game's state:
    Code (csharp):
    1. int width = _gridRenderer.To.x;
    2. int height = _gridRenderer.To.y;
    3.  
    4. Tile[,] map = new Tile[width, height]();
    You decide what your tile class needs to store. If you have an object in the world you can get its tile-coordinates like this:
    Code (csharp):
    1. GameObject object;
    2. int x = grid.WorldToGrid(object.transform.position).x;
    3. int y = grid.WorldToGrid(object.transform.position).y;
    And now you can use x and y as an index into your map array. Range finding can be done using .Net Linq queries, so you don't even need any extra frameworks for that.

    EDIT:
    It isn't even about being slim, it is about being general. With a kit what happens is that the developer has envisioned a certain way to write your game. This is great if that is exactly how you want your game to work, but if it is not you end up having to fight kit's own quirks, which defeats the whole point. I designed my plugin to be flexible, so you can integrate it into your code the way you want. Users can create their own extension methods, renderers, and even entirely new grid types. This isn't just theory, one user did in face create a guitar grid that resembles the way the strings and frets are arranged on a real guitar, something the included grids cannot do.
     
    Last edited: Mar 26, 2017
  12. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    202
    Sure. Being general, slim, whatever the motivation, different frameworks serve different purposes. Of course you could take the above to its logical conclusion, and say that a deeply opinionated developer should code everything from scratch, so it's all exactly how they want it! I personally try to find a balance, where I can benefit from others' frameworks, utilising their APIs to handle 'busy work', while being in charge of the overall architecture and implementation.

    You can include things like path and range finding in semi-generic ways, using callback functions to handle cell cost calculations etc. You can still have a user generated 'cell', and the path/range finding is simply the relationship between cells and their neighbours, little is opinionated, they're more like helper functions for common grid relationship behaviour. And you can make those functions completely optional. That's how Grids 2 operates, however while it's incredibly flexible, some of that flexibility has resulted in it becoming frustratingly obfuscated. So I'm on the hunt for a slightly less generic implementation, hehe.

    You're of course right that you can never guarantee more specific functions suit exactly the purpose or implementation that a developer requires, and if its your goal for your asset to remain general, that's perfectly fine!
     
  13. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    That is the idea behind Grid Framework, it's just that different people have different needs for granularity. I am always open for suggestions, what would your idea of a general pathfinding support be? I am not telling you to hold your breath for it instead of buying another asset, but I still think that opinions from non-customers are also valuable.
     
  14. gumboots

    gumboots

    Joined:
    May 24, 2011
    Posts:
    202
    Well general pathfinding to me is being able to say "give me the cheapest path to get from cellA to cellB", a callback function would allow me to determine the movement cost between cells. e.g.:

    Code (CSharp):
    1. int GetCellMovementCost(cell1, cell2) {
    2.     return cell1.height < cell2.height ? 2 : 1;
    3. }
    I'd say indicating whether diagonal movement is allowed would be useful as well. But I am thinking solely from a square/rectangle-centric position.

    And you could employ similar behaviour for range finding. Though range finding gets more complex because you potentially start dealing with line of sight. However the two go hand in hand for my requirements, I'm looking for a solution to handle all things grid and grid movement.

    I agree entirely that different people have different needs, and it makes perfect sense that your asset's purpose is to just handle the former!
     
  15. jrDev

    jrDev

    Joined:
    Nov 5, 2008
    Posts:
    1,564
    Hello hiphash,

    I am looking into purchasing this package to use in a project to build a block puzzle stacking game (Pokemon puzzle league, Puyo-puyo etc) and I am planning to use Playmaker. Would this be a good package to get my project going? What will and what won't this package help me with? Looking forward to response.

    Thanks,
    jrDev
     
  16. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Hello jrDev,

    Grid Framework can help you translate from grid- to world coordinates and vice-versa. You could keep track of your game's state in an array like this:
    Code (csharp):
    1. // Cell is some custom type representing the state of one field
    2. Cell[width, height] gameState;
    3. // Translate the position (i, j) of a field in the matrix to a world position:
    4. RectGrid grid;
    5. var position = grid.GridToWorld(new Vector3(i, j, 0));
    With this you can write all your logic in grid coordinates and let Grid Framework translate an entry in the state array to a world position for placing your game pieces in the world. Here is an idea:
    Code (csharp):
    1. void SpawnTile(int i, int j, Cell tile) {
    2.     gameState[i, j] = tile;
    3.     SpawnSprite(tile.sprite, grid.GridToWorld(new Vector3(i, j, 0)));
    4. }
    5. void MoveTileDown(int i, int j) {
    6.     gameState[i, j +1] = gameState[i, j];
    7.     gameState[i, j] = null;
    8.     MoveSprite(-grid.Up);
    9. }
    As you can see the functions that implement the tile movement don't know anything about the world, and the (hypothetical) functions that implement sprite movement don't know anything about the game's rules.

    How the game is supposed to work is up to you. Grid Framework does not make any assumptions about the game itself, so it is completely up to you what the "Cell" type actually is and how to build that array (assuming you even want to use one). Grids are not some finite collection of points, they are grid in a mathematical sense (infinite in size, constant memory use).

    This is at least what I can think of for such a type of game. If you have any more concrete questions let me know.
     
  17. dre788

    dre788

    Joined:
    Feb 15, 2013
    Posts:
    35
    Hello, I recently updated to 2017.2 beta and I got this error.
    Code (CSharp):
    1. Assets/Plugins/GridFramework/PlayMaker Actions/FsmGFStateAction.cs(19,29): error CS0104: `Grid' is an ambiguous reference between `UnityEngine.Grid' and `GridFramework.Grids.Grid'
    2.  
    There was a folder called "Test" where a file was giving me the same error but I deleted it. Is there anything on my end I can do to fix this?

    Thanks for the great asset and thanks for your time.
     
  18. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Hello,

    Looks like Unity is adding their own grid components and the two names are colliding. Can you please try the following: in the file Assets/Plugins/GridFramework/PlayMaker Actions/FsmGFStateAction.cs add the following line:
    Code (csharp):
    1. using GFGrid = GridFramework.Grids.Grid;
    after
    Code (csharp):
    1. using GridFramework.Grids;
    and then change any occurrence of Grid to GFGrid. The extra line solves the naming conflict by aliasing one of the classes to another name.
     
  19. dre788

    dre788

    Joined:
    Feb 15, 2013
    Posts:
    35
    Excellent, that seems to have done the trick. Thanks for the speedy rely. You rock! Now I need to get playmaker itself to act right.
     
  20. jovalent

    jovalent

    Joined:
    May 27, 2017
    Posts:
    4
    Is there going to be a new version for Unity 2017? If so, when and will it be a free or a paid upgrade?
     
  21. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Yes, I'll get to it today, I just finished another project a few hours ago. The fix is a simple search&replace as outlined in the post above yours, but I cannot tell you when the update will be approved by the Asset Store team, so please use the fix above until then. The update will be free of course, a compatibility fix is not worth paying for, I'm not that greedy :)
     
    jovalent likes this.
  22. jovalent

    jovalent

    Joined:
    May 27, 2017
    Posts:
    4
    Really I was asking because I want to buy this product but not if I'm going to have to upgrade in a month.
     
  23. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I don't have plans for a major update at the moment, so no paid updated for the foreseeable future. The problem outlined above only happens if you want to use the Playmaker actions, for everyone else the current version works fine.
     
  24. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    Im getting an error after importing on unity 2017.20b10, it looks like unity is making his own grid system, are you planning on add support for unity 2017 soon?
     
  25. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Are you using the latest release? I updated for 2017.1 a couple of week ago, so it should be working. Can you please post the error messages you are getting?
     
  26. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
  27. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Weird, how did that one slip past me? You can for the time being delete all the files under Plugins/GridFramework/Test, they are not needed for functioning.
     
  28. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
  29. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    So it looks like unity its implementing its own grid system, its pretty basic and not well documented. Its a shame since I wanted to start scripting today (I buyed grid framework yesterday), but it looks like you have to do a lot of work to make it not collide with unity grid, so now I have to wait for your update, or unity adding more functionality to unityengine.grid. how much time do you think it will take you? Im pretty noob at scripting but it looks like your class grid needs to have a different name, maybe gridF or something, and update all the scripts that use that class.
     
  30. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I have made a fresh Unity project and imported Grid Framework, but I am not getting any compilation errors for some reason (see attached image). I don't even understand why, because this should be a name conflict.

    I'll have to try and fix this issue blindly, which might take a while. Until then you can open the offending files and fix it manually: Double-click the error message in Unity and first add after this line:
    Code (csharp):
    1. using GridFramework.Grids;
    the following:
    Code (csharp):
    1. using GFGrid = GridFramework.Grids.Grid;
    Now rename every time the type Grid is being used to GFGrid. Double-clicking the error message in Unity will take you straight to the offending line. Sorry for taking so long to come back to you about this, but you contacted me yesterday past midnight in my time zone :)

    Yeah, it's pretty useless right now, at the moment it looks like something that's still experimental.
     

    Attached Files:

  31. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Oh, now I see, you are using the beta of 2017.2, not 2017.1. I got it figured out now and I'll see that I get the update submitted today, but there is no telling how long it will take Unity to approve of it. If you are familiar with the Unix patch tool you can use these two patches to fix the files automatically. Run the patches from the Assets directory of your project. For Plugins/GridFramework/Editor/AlignPanel.cs:
    Code (csharp):
    1.  
    2. 4a5
    3. > using GFGrid = GridFramework.Grids.Grid;
    4. 85c86
    5. <        private Grid AnyGrid {
    6. ---
    7. >        private GFGrid AnyGrid {
    8. 87c88
    9. <                return (Grid)_rectGrid ?? (Grid)_hexGrid;
    10. ---
    11. >                return (GFGrid)_rectGrid ?? (GFGrid)_hexGrid;
    12. 148,149c149,150
    13. <            var currentGrid = (Grid)_rectGrid ?? (Grid)_hexGrid;
    14. <            var grid = EditorGUILayout.ObjectField(label, currentGrid, typeof(Grid), true);
    15. ---
    16. >            var currentGrid = (GFGrid)_rectGrid ?? (GFGrid)_hexGrid;
    17. >            var grid = EditorGUILayout.ObjectField(label, currentGrid, typeof(GFGrid), true);
    18.  
    19.  
    For Plugins/GridFramework/Editor/MenuItems.cs:
    Code (csharp):
    1.  
    2. 4a5
    3. > using GFGrid = GridFramework.Grids.Grid;
    4. 93c94
    5. <        private static void CreateGrid<TGrid, TRend>(string name) where TGrid : Grid where TRend : GridRenderer {
    6. ---
    7. >        private static void CreateGrid<TGrid, TRend>(string name) where TGrid : GFGrid where TRend : GridRenderer {
    8.  
    9.  
     
  32. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I have submitted the update to Unity, but it will take a few days for them to approve of it. If you want to start scripting now you will have to fix it manually to bridge over that time.
     
  33. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    Yeah I fixed it since yesterday, thanks a lot for the quick response!
     
    hiphish likes this.
  34. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    Simple question, I am making a game where the player needs to interact with the cells and vertices of a grid, so i need to store and compare a matrix of cells and a matrix of vertices to give them values. My first instintic after reading the documentation was to make 2 separate grids, one for the cells values and one for the vertices values, witch in fact seems to work ok. But now im wondering, do you have any way to acces cell info on your grids? they have a matrix or they simple are vector 3 positions?

    Thanks in advance and sorry for bad english.
     
  35. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Grids are infinitely large, so there is no way to give every vertex or cell data by default, but you can easily make one yourself:
    Code (csharp):
    1. RectGrid       grid;  // The grid you want to use
    2. Parallelepiped rend;  // The grid's renderer
    3.  
    4. int w = Mathf.RoundToInt(rend.To.x - rend.From.x);  // Width of the grid
    5. int h = Mathf.RoundToInt(rend.To.y - rend.From.y);  // Height of the grid
    6.  
    7. // Store the vertex data here:
    8. int[,] vertexData = new int[w, h];
    Here I am storing an integer for every vertex, but you can use any data type you want. When you have the X- and Y coordinates of a vertex you can access the element in the matrix like this:
    Code (csharp):
    1. int VertexDatum(Vector3 v) {
    2.    var x = Mathf.RoundToInt(v.x) - Mathf.RoundToInt(rend.From.x);
    3.    var y = Mathf.RoundToInt(v.y) - Mathf.RoundToInt(rend.From.y);
    4.  
    5.    return vertexData[x, y]
    6. }
    I subtract the From.x coordinate because your grid could start for example at an x-coordinate of 3, and then a point with x-coordinate 5 would be the second index in the matrix, not the fifth. If all your grids start at (0, 0) everything simplifies of course.

    Nah, your English is fine. You should see the stuff I have to put up with sometimes :)

    EDIT: BTW, the update got approved by the Asset Store team, give it a try now.
     
  36. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Grid Framework version 2.1.6 released
     
  37. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Just a quick heads-up: I'll be away for a week; I have a notebook with me so I can answer questions, but it might take me a bit longer to reply. I'll update this post when I'm back.
     
  38. Kruko

    Kruko

    Joined:
    Jan 26, 2016
    Posts:
    127
    Hello and sorry for noobish question, but your asset seems good, but i don't know if it can help in what i need so i need your advice.

    I'm using Playmaker and Core GameKit for spawning (instantiating) enemies. Some have defined spawn points and move via waypoint, other are spawned singularily, while some are spawned in squadron patterns. I created some empty objects for basic spawn points, but i need more variety which can be achieved through more spawn points that would be selected randomly. Below you can find an image which crudely represents what i need.
    [​IMG]The grid is quite obvious (i prefer it is rectangular if possible), red line is the camera frustum, blue dots are grid intersections, and green dots would be grid cells. So, i need a two-dimensional grid which could generate (empty or otherwise) game objects on intersections or cells which i can then add to the array and choose randomly as a spawn point when instantiating the enemies. I say generate because i can do this on my own basically, but it would take hundreds of points in space and a tiresome editor work (i'm not much of a coding guy to do it differently).

    Any advice is welcome, if your asset is capable of something like this with Playmaker and no coding then great.
     
  39. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Hello,

    This can be done fairly simply. From what I can tell from your description you want to generate spawn points on both vertices (intersections) and faces (cells). It would be easier to have two grids: one for show (what you see in your drawing) and one that has half the spacing so that all the spawn points are on its vertices.

    Assuming you have a function that instantiates a spawn point at given world coordinates you could then do the following:
    Code (csharp):
    1. RectGrid grid;  // the grid you want to use
    2. int fromX, toX, fromY, toY;  // the range you want to spawn objects in
    3. // Generate two random numbers
    4. var rand = new Random();
    5. x = rand.Next(fromX, toX);
    6. y = rand.Next(fromY, toY);
    7. // Instantiate the spawn point
    8. PlaceSpawnPoint(grid.GridToWorld(new Vector3(x, y, 0)));
    What we did first was to generate two random numbers within a given range using regular .NET methods. We then used those two numbers as grid-coordinates which we then translated to world-coordinates to place the spawn point at.

    The next question is how to get this range we used in the beginning. We have the position of the camera, its size and its aspect ratio. From these we can compute the grid-coordinates of its frustum using some simple math. I'm at vacation at the moment, so I don't have access to my stuff. It's just some basic math, I'll write up the formula on Thursday if you are interested.
     
  40. Kruko

    Kruko

    Joined:
    Jan 26, 2016
    Posts:
    127
    Hello,

    Thank you for a swift answer and excuse my late response. I didn't expect such a thorough answer to be honest. I managed to do it with your help, thank you.
     
    hiphish likes this.
  41. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    Edit: Never mind, I found the readme file for vectrosity!
     
    Last edited: Oct 4, 2017
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Only the example files (Plugins/GridFramework/Examples/Vectrosity/*.cs) need that definition. If you don't want to run the examples you don't have to worry about it. The definitions are needed to prevent compilation errors from calling Vectrosity methods when users don't have Vectrosity installed.
     
  43. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    So why would I get a vectrosity vertical grid when my grid has a diferent orientation? GetVectrosityPoints(); doesnt return points from worldspace?

    [​IMG]

    Im thinking its because I have my grid values to x and y, and some rotation in the actual transform of the grid. But its weird because I havent had any trouble using gridToWorld, so I was expecting GetVectrosityPoints to calculate that before making the points.

    [​IMG]

    I tried rotating the rect transform of the actual vectrosity grid but the grid looks off. Any advice on how to solve this? Maybe I have to work on the actual GetVectrosityPoints method and change the in y for -z, or reverse, set the grid Parallelepiped rigth and change all the calculations on my data structure... but before trying that, is there a simplier way?
     
    Last edited: Oct 5, 2017
  44. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
  45. JohnGate

    JohnGate

    Joined:
    Oct 22, 2013
    Posts:
    487
    @hiphish
    Hi there, I'm looking for a Hex based grid to make a puzzle word game.
    https://lh4.ggpht.com/iic0fOqBOd6Tgv324tGsWY9G8dY_uKT8JLRYEgvfOnwxWIZvhuGRFp9uj1xCj0mNGA=h310

    There is aleady a dedicated word game asset with hex support and algorithms to fill hex grid with predefined words. However it is not supported anymore so doesnt worth.

    your plugin looks promising and you provide great support.
    So my question is can you provide a sample algorithm that Fill the hex grid from a pre-given list of words and In case Hex Grid run out of words list and still have empty cells then fill hex grid with random characters.

    Thanks
     
  46. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Sorry, I have had trouble with my apartment and property damage, I have barley had time for reading my emails. How exactly are you rotating your grid? At runtime or in the editor? Do the examples that come with Grid Framework work correctly for you?

    Hello,

    It can be done, but Grid Framework is not a "just add water" type kit, so you'll have to write some code of yours to get it to do what you want. I'm going to assume you have a type for your word tiles (I'll call it Tile) and you have the code to place a time at some arbitrary world position (call the function PlaceTile). Placing a tile according to its grid coordinates is easy then:
    Code (csharp):
    1. Tile t;
    2. HexGrid g;
    3. Vector3 gridPosition;
    4.  
    5. // Assuming you use the rhombic-up coordinate system
    6. PlaceTile(t, g.RhombicUpToWorld(gridPosition));
    However, there is no algorithm that finds those grid positions to will the playing field with predefined words. That's a very specialised task that's outside the scope of a general-purpose framework. You will either have to come up with an algorithm of your own or find an existing solution. With that said, once you can generate pairs of tiles and positions you can pass them to the above one-liner to place those tiles on the screen. This is the advantage of a general-purpose framework, you can combine it with other general-purpose frameworks any way you want.
     
    JohnGate likes this.
  47. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    In editor, the grid is basically static at 0,0,0 position and -90,0,0 rotation. The examples all work fine, im using this code to get the points:

    Code (CSharp):
    1. var points = gridRenderer.GetVectrosityPoints();
    2. for (var i = 0; i < points.Count; ++i)
    3. {
    4.     var point = points[i];
    5.     points[i] = point - transform.position;
    6. }
    Basically, the same code as in the demos.
    And I have only 1 grid on scene.
     
    Last edited: Oct 8, 2017
  48. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Try this instead:
    Code (csharp):
    1. var points = gridRenderer.GetVectrosityPoints();
    2. for (var i = 0; i < points.Count; ++i) {
    3.     points[i] = transform.InverseTransformPoint(points[i]);
    4. }
    It's the code from the example where the grid bounces around. The points on the first line are in world coordinates, but you want them in local coordinates, hence the use of InverseTransformPoint.

    EDIT: To elaborate, the difference is that InverseTransformPoint takes also rotation into account, while doing a simple point - position only takes location into account.
     
    Last edited: Oct 9, 2017
  49. rubenpvargas

    rubenpvargas

    Joined:
    Jul 18, 2012
    Posts:
    16
    Thanks! Its working fine now, I didnt know about InverseTransformPoint, very usefull, I have learned a lot taking a look at your code, thanks for the great kickstart into coding!
     
    hiphish likes this.