Search Unity

Grid Framework [scripting and editor plugins]

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

  1. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142

    Attached Files:

  2. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    I need to know what the scale of your GameObject is, not your model. In Unity every object in a scene has a Transform component, which has a scale. As far as Unity is concerned that's the scale of your object. The 3D mesh can be bigger or smaller than that, it is all subject to the scale of the Transform. In other words, if your object has a scale of (1,1,1) but your mesh looks like it's (3,2,1) large, Unity will still consider your object to be only (1,1,1) world units large.

    I'm not exactly sure what you want. The grid is a 3D world object and it can be resized to any size. If you know the pixel : worldUnit ratio of your camera you can just multiply the grid's spacing with that number. Is that what you want?
     
  3. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    If you see the block in here - http://design.tutsplus.com/articles/create-a-block-game-interface-in-illustrator--vector-5269, it has its own grid lines. The background has 18 columns. So if I configure the grid for 18 cols, when I place this grid over the image and resize it dynamically, I am just concerned there might be some misalignment between the grid cols and the background cols. I need the grid to constrain the object movement, but I would also like to use background for the visual effects.

    Thanks,
    Syed
     
  4. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Just to make sure you are on the same page as I am: grids in Grid Framework have no "size", they are infinitely large. The limited area one sees is just visual representation. That area can be adjusted arbitrarily, it's a Vector3 for the lower limit and a Vector3 for the upper limit. The thing that defines a grid are its spacing and the Transform of its gameObject (grids are components in Unity terms), i.e. the position of the origin and the rotation.

    For a Tetris game you will want one grid for the playing field and then the blocks will be just regular block object that are moved around in the grid. Of course the blocks could have grid components on their own, but I don't really see the point in that.

    Your playing field would be modelled by a two-dimensional array. Here is how you can generate it:
    Code (csharp):
    1. GFRectGrid grid; // the background grid
    2. int width, height;
    3. bool matrix[,] = new bool[width, height];
    4. // I'm using boolean here, but you can use any type really
    5.  
    6. // only if you want to grid to be visible
    7. grid.renderFrom = Vector3.zero;
    8. grid.renderTo   = new Vector3(width, height, 0);
    9.  
    10. // adjust spacing
    11. grid.spacing *= worldToPixelRatio;
    12.  
    13. // to move a block downwards one grid unit:
    14. Transform block;
    15. block.position += -grid.up;
    16. // to align a block with the grid:
    17. grid.AlignTransform(block);
    18.  
    19. // get the grid coordinates of a block:
    20. Vector3 gridCoordinates = grid.WorldToGrid(block.position);
    21. // convert to world coordinates:
    22. block.position = grid.GridToWorld(gridCoordinates);
    23.  
    24. // matrix indices of a block:
    25. int i = Mathf.RoundToInt(gridCoordinates.x);
    26. int j = Mathf.RoundToInt(gridCoordinates.y);
    And so on. Since everything is based on floating point numbers things will never 100% align, but it doesn't matter as long as the result looks good enough.

    Take a look at this example:
    http://hiphish.github.io/grid-framework/examples/lights/
    The cubes were aligned in the editor and the sector pieces were generated and placed at runtime. All using the Grid Framework API.
     
  5. civmeup

    civmeup

    Joined:
    Feb 5, 2015
    Posts:
    2
    Hi, your plugin looks great.

    I'd like to you whether you have any insights into using your grid plugin to create a sphere, like in this thread
    http://forum.unity3d.com/threads/hexglobe-hex-based-planetary-globes-for-strategy-games.156601/
    The thread itself is promoting a plugin to do exactly that, but I really like your style and I think you've implemented very well, so I'm more interested in using GF as a base to create something similar.
    The theory of the sphere is pretty well covered in the first post in that thread, it's based on an icosahedron (20 triangle faces, split into hexes), so the globe is all hexes _except_ for 12 pentagons where the vertices of the 20 base triangles meet
    Anyway, That's what I'm going to do, and I'm hoping to use GF to do it, so I'd love your input...

    Thanks
     
  6. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Hi,

    No, I don't have that. The idea of taking an icosahedron and tessellating it is pretty clever, but as you noted is has downsides where the triangles meet. It's simply impossible to cover a sphere using hexagons; that reminds me how when I was little I was always getting annoyed that footballs were covered using two shapes, but no matter how I tried to re-arrange the hexagons in my head they would never fit.

    That's a good idea for a new type of grid though, I'll add it to the list. I've set my next goal to be spheric grids with celestial coordinates already (think longitude and latitude) But don't hold your breath, if that plugin is offering what you need I can't compete for the time being.
     
  7. civmeup

    civmeup

    Joined:
    Feb 5, 2015
    Posts:
    2
    Thanks for the response.
    I think it's the best approach I've seen to creating an alllllllmost hex globe. the 12 pentagons are acceptable from a gameplay standpoint, (if not from an ocd perspective)
    Well, I'm going to give it a crack, and I'm going to use GF as the basis. PM me if you like, we could work on it together...
     
  8. SuHwanK

    SuHwanK

    Joined:
    Dec 30, 2014
    Posts:
    43
    Hi, again.
    i found grid framework document in unity help tab.
    anything else? like pdf manual.(Capture picture on your youtube video)

    And i dont found "how use to vectrocity line"
    thank you!
     

    Attached Files:

  9. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Ah, I'm an idiot for having that picture still up. The current documentation is all HMTL since it's better to read when it allows you to open pages in tabs and it has a search feature. The content is the same though, just pick a topic from the sidebar. The PDF manual was originally written by hand, but keeping the API consistent and up to date was a pain, that's why I switched a documentation generated by Doxygen. Now the API documentation is written directly in the code, where it belongs.

    For Vectrosity you first need the Vectrosity plugin. Vectrosity needs an array of vertices and to get that you use the `GFGrid.GetVectrosityPoints` method (look it up in the documentation). The method simply fetches the vertices needed and returns them in an array suitable for Vectrosity. From there on your data is outside the domain of Grid Framework.
     
  10. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    Hi, I am trying to do a basic Grid setup. I did the following steps:

    1. Create a new scene.
    2. Attach the GFGrid Render Camera script to the Main camera.
    3. Drop a 3d Grid object onto the scene.
    4. The camera is at (0, 1, -10). The grid is at (0, 0, 10).

    The grid lines just will not show up whether I run the scene or look at the camera in the scene view. Any idea what I am missing?

    Updated: Never mind. It was the Camera. I had to add the MainCamera tag which is probably being used by the Render script. It is working now.

    Thanks,
    Syed
     
    Last edited: Feb 11, 2015
  11. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Yes, by default only the main camera renders the grid, it's in order to prevent auxiliary cameras from rendering it when you don't want to. There is a flag on the script that lets you render the grid even if the camera is not your main one.
     
  12. alok-kr-029

    alok-kr-029

    Joined:
    Jan 10, 2013
    Posts:
    22
    Hi
    How can I get the gameobject exist in pirticular coordinate of Grid like (2,2) .
    coordinate of the grid I am getting by
    Vector3 vec = grid.WorldToGrid(transform.position);
     
  13. toxicfrog

    toxicfrog

    Joined:
    Jun 13, 2014
    Posts:
    6
    Hi hiphish,

    I just purchased Grid Framework for use with Playmaker, and I'm hoping you can give me a quick assist to help me wrap my head around how they work together.

    I've got a 5x5 grid with spacing set to 1. I'm treating the grid as if it were a 2D grid (no Y will be used). I have a tile that is sized 1x1 to fit perfectly in each grid space.

    I want Playmaker to assess the grid, then create a gameobject (the tile) in the center of each grid square.

    Can you describe how I'd use Playmaker to create this tile gameobject in the center of each grid space? Once I figure this out I think I'll have enough understanding to take it from there and work out the rest myself.

    Thanks a lot!
     
  14. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Do you mean you want to place an object at grid position (2,2)? Then use to opposite of WorldToGrid: GridToWorld:
    Code (csharp):
    1. Transform myObject;
    2. GFGrid myGrid;
    3. myObject.position = myGrid.GridToWorld(new Vector3(2, 2, 0));
    I set the third coordinate to 0, you can set it to whatever you want.

    I don't use Playmaker myself, so I don't know how to create game objects, you will have to ask the Playmaker developers about that. Now, once you have the tile you need to set its position to your liking. Use the grid coordinates of your desired destination. That's a Vector3 type. Run the GridToWorld building block on the grid position using your grid of choice and you get the world position coordinates. Assign that position to your tile and it will be in place.

    Whether your grid is 2D or 3D doesn't matter, it is always technically a 3D grid. Just keep the Y-coordinate a constant number, like 0, and it works like a 2D grid.

    If you are using a rectangular grid keep in mind that the full coordinates are on the vertices, i.e.:
    Code (csharp):
    1.  - - - - - -
    2. | | |X| | | |
    3.  - - - - - -
    4. | | | | | | |
    5.  - - - - - -
    The X does not have coordinates (2, 1), it has the grid coordinates (2.5, 1.5).
     
    alok-kr-029 likes this.
  15. toxicfrog

    toxicfrog

    Joined:
    Jun 13, 2014
    Posts:
    6
    Thanks, hiphish!
    That's all I needed to work it out. For anyone wondering, here's how I did it:

    Created Rectangular Grid, set Render to and Render From to 0,0,0 (Relative Size).

    Created 'GridSettings' empty game object. All it does is store FSM integers "GridX" and "GridZ", which are visible in the Inspector. This lets me change the size of the grid anytime through this object.

    Created 'GridBuilder' empty game object. Added Playmaker FSM to:
    1. Get GridX and GridZ integers
    2. Convert GridX and GridZ to floats
    3. Create Vector3 (GridX, 0, GridZ)
    4. Store Vector3 as 'RenderToValue'

    Created 'GridTiles' empty game object. Added Playmaker FSM:
    Using local 'CurrentX' and 'CurrentZ' integers (set initially at 0):
    1. Get GridX and GridZ from GridSettings FSM
    2. Compare CurrentX to GridX. If CurrentX is greater than GridX, goto 7.
    3. Convert CurrentX and CurrentZ to floats, create 'GridPosition' Vector3
    4. Use GridToWorld to convert GridPosition to WorldPosition
    5. Create GameObject 'Tile' at WorldPosition
    6. Add +1 to CurrentX and goto 2

    7. After all GridX is finished, reset CurrentX to 0 and add +1 to CurrentZ.
    8. If CurrentZ is greater than GridZ, finish
    9. Goto 2

    Worked like a charm - thanks for this great module!
     
  16. alok-kr-029

    alok-kr-029

    Joined:
    Jan 10, 2013
    Posts:
    22


    Thanks I understood your concept ,Now I will work it out
     
  17. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    Hi, I am looking at the Sliding Puzzle example. I have a geometric shape which I need to rotate along its y-axis even as I move the shape between blocks. What is the best way to do this? I looked at the AlignTransform function in CFGrid.cs (below). I always get whacked when I apply rotation to the child object and the parent has its own rotation. What is the best fail-proof way to approach this so I could rotate a triangle on its y-axis through 90 degrees on each move?

    Thanks,
    Syed
     
    Last edited: Feb 15, 2015
  18. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    The main idea of the example is that for every block you clamp its position to legal values. Let's assume you have a T-shaped Tetris block in a plane. That block is make out of four cubes, so we need to monitor every cube individually. When the player clicks the block mark all the grid tiles of the cubes as free. Then, as the player tries to move the T-shaped block you check for every individual cube whether the position it is moved towards is legal. Only if all cubes pass does the entire block move.

    If you want to add rotation to the mix you do the same thing: to an imaginary rotation of your block, check if all cubes are in a legal position and only then apply the rotation. Since Everything is made of block the imaginary rotation does not need to be a real smooth continuous rotation, it can be a hard discrete 90° snap:
    Code (csharp):
    1.  - - - - - -         - - - - - -
    2. | | | | | | |       | | |X| | | |
    3. - - - - - -         - - - - - -
    4. | |X|X|X| | |  ==>  | | |X|X| | |
    5. - - - - - -         - - - - - -
    6. | | |X| | | |       | | |X| | | |
    7. - - - - - -         - - - - - -
    The point is that you know by how many grid coordinates each cube will shift. The `AlignTransform` method aligns the position of an object to the nearest reasonable grid coordinates. The `rotate` parameter of the method makes the object's rotation match the rotation of the grid, which will mess up any other rotation you have. Let's say your grid is flying through space and spinning around, in that case you would want your give you spin around as well, that's wheat the parameter is for. if you want to apply your own rotation to the cube on top of that you will have to combine the quaternions.



    On an unrelated note, please do not publish my code, even in parts in public. It's no big deal this time, but please edit it out of your post. You shouldn't rely on the code to make things work, use the API documentation. I can change things in the code at any time without notification, only what is written in the documentation is set in stone. As long as the outside interface (i.e. the "what") does not change I can completely revamp the inner working (i.e. the "how"). (of course if you want to read the code for other reasons feel free)
     
    Last edited: Feb 15, 2015
  19. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    Ok. Thanks! I edited my code to remove the code snippet.
     
  20. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    I've been using Grid Framework for a couple of years now. Very nicely done!

    I just updated from Unity 4.5 to 4.6.2. At the same time, I updated both Grid Framework to 1.7.3 and Vectrosity to version 4.0.5 which has some major changes based on Unity 4.6. After taking the comments off of GF's Vectrosity demo scripts, I tried running the GF Vectrosity demo. While I can see the grids bouncing in the scene view, the game view is completely black.

    I checked this thread a bit looking for mention of changes to work with Vectrosity 4 but found none. Does GF work with Vectrosity 4?

    Edit: Just answered my own question. I'm now seeing compile errors in the 4 example scripts related to the API changes in Vectrosity. While the example scripts aren't critical, I'm hesitant to upgrade GF and Vectrosity in my development project without knowing that GF has made any needed adjustments to interfacing with Vectrosity. Do you have an ETA on an update?
     
    Last edited: Feb 17, 2015
  21. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    I had a look into to the issue, it's safe to update. The issue is the constructor of the VectorLine class, here is one of them defined in Vectrosity 3:
    Code (csharp):
    1.  
    2. VectorLine (name : String,
    3.     points : Vector2[] or Vector3[],
    4.     color : Color,
    5.     material : Material,
    6.     lineWidth : float,
    7.     lineType : LineType = LineType.Discrete,
    8.     joins : Joins = Joins.None) : VectorLine
    9.  
    This constructor no longer exists in Vectrosity 4, but it was used in my example. I'll update it so it compiles fine in Vectrosity 3 and 4, but you can freely update things, the Grid Framework classes don't need any changes.

    I'm currently preparing things for Unity 5, I recently got my beta key and Unity change a number of things how assets are managed. If you want to make the examples work in the meantime, you must find the offending constructors, like this one:
    Code (csharp):
    1. gridLine = new Vectrosity.VectorLine("Rotating Lines", grid.GetVectrosityPoints(), Color.green, lineMaterial, lineWidth);
    and remove the colour part. Instead set the colour in the next line of code explicitly directly after the vector line has been constructed:
    Code (csharp):
    1. gridLine = new Vectrosity.VectorLine("Rotating Lines", grid.GetVectrosityPoints(), lineMaterial, lineWidth);
    2. gridLine.color = Color.green;
    For arrays of colours you have to use
    Code (csharp):
    1. gridLine.SetColors(colorArray);
    The offending resizing line of the resizing grid needs to be replaced with these two lines:
    Code (csharp):
    1. gridLine.points3.Clear();
    2. gridLine.points3.AddRange(grid.GetVectrosityPoints());
     
    Last edited: Feb 18, 2015
  22. ghost012

    ghost012

    Joined:
    Jan 3, 2013
    Posts:
    13
    Hi, i'm about to buy gird but there is one thing i would like to know.

    can i give individual grid(hexagon, quad) property's or is it better to manually place triggers on top of them?
    For example for a strategy game, going a level up would consume 2 movements or swamp or forest property's.

    And how does Grid handle height for moving-snapping ?

    I see there is a tutorial video on making levels with grid, grid will spawn in "terrain" blocks, can this also be used with the height's?

    And if i understand it right, the orientation of the gird doesn't matter? like you can have girds on walls, sealing ect and still have it work with snapping?
     
  23. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Hi,

    The grid is an infinitely large coordinate system, so there are no "properties" per vertex/face/box, that makes it so lightweight. It's best if you place object (triggers or whatever you want) in the spots you want.

    All grids are three-dimensional, the rectangular grids are an infinite number of boxes while the hex- and polar grids are flat layers stacked on top of each other (infinite amount of layers). Grids are also Unity components, so they take on the rotation and position of whatever object they are attached to. The coordinate system rotates with the object.

    Snapping work always relative to the current rotation of the grid. For instance, if you have a bunch of spheres and your grid is at an angle your spheres will be aligned with the grid and at an angle as well. You can choose whether you want your object to have the same rotation as the grid or not.

    Since the grids are all three-dimensional there is no problem with the height. In fact, it has to be that way, because I don't know what a developer might consider to be the "height". Some use the Z-axis as the height, others use the Y-axis. It doesn't matter, you could even use the X-axis.
     
  24. Kaldorei

    Kaldorei

    Joined:
    Aug 12, 2010
    Posts:
    112
    Hello,

    I just purchased Grid Framework and its really awesome, i've spotted a little bug that prevent me to use it actually, combining deferred mode on rendering path + any AO postprocess included with Unity will break the depth sorting of the grid



    Best Regards
     
  25. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Hello,

    Have you tried using a different shader? You can drop any shader into the Shader field of the grid. The standard shader is not really meant to be the ultimate shader that fits everyone, it's just a simple shader that gets lines on the screen. Here is what the manual says about deferred lighting:
    My guess is that since the shader is lit it is rendered together with the lighting on top of the cube. I'm afraid I can't test it myself since deferred lighting and Ambiant Obscurance are Pro features. At least deferred lighting is included with the Unity 5 beta, but I cannot reproduce your problem:

    You can find an unlit shader here, maybe that solves the problem:
    http://owlchemylabs.com/content/
     
  26. Kaldorei

    Kaldorei

    Joined:
    Aug 12, 2010
    Posts:
    112
    Hello,

    I've tried with many shaders even mine with customized renderqueue the problem is ONLY with combination of deferred + AO postprocess, if you use just deferred you won't have the problem.

    Meanwhile in forward rendering it's working quite well (even if it wont fit in my need since i really need deferred rendering + AO) your plugin is a beautiful piece of framework gj
     
    Last edited: Feb 23, 2015
  27. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Here is a stripped down minimum working example of how to grid rendering works:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class GLtest : MonoBehaviour {
    4.     public float     _offset = 5.0f;
    5.     public Transform _cube;
    6.     public Material  _material;
    7.  
    8.     private const string DefaultShader = "Shader \"Lines/Colored Blended\" {" +
    9.         "SubShader { Pass { " +
    10.         "    Blend SrcAlpha OneMinusSrcAlpha " +
    11.         "    ZWrite Off Cull Off Fog { Mode Off } " +
    12.         "    BindChannels {" +
    13.         "    Bind \"vertex\", vertex Bind \"color\", color }" +
    14.         "} } }";
    15.  
    16.     void OnPostRender() {
    17.         Vector3 start, end;
    18.  
    19.         start = _cube.position - _offset * _cube.right;
    20.         end   = _cube.position + _offset * _cube.right;
    21.  
    22.         if (!_material) {_material = MakeMaterial();}
    23.         _material.SetPass(0);
    24.  
    25.         GL.Begin(GL.LINES); {
    26.             GL.Color(Color.green);
    27.             GL.Vertex(start);
    28.             GL.Vertex(end  );
    29.         }
    30.         GL.End();
    31.     }
    32.  
    33.     private Material MakeMaterial() {
    34.         return new Material(DefaultShader);
    35.     }
    36. }
    If you attach this script to a camera and then assign a cube to the cube field you will see a green line rendering horizontally through the cube. You can leave the material unassigned and it will use a default shader. Does the problem still persist? This might be a bug in Unity, so we need to make sure we can reproduce it with a minimum example.

    Alternatively, and I'm sure this is not the answer you wanted to hear, there is Vectrosity. Grid Framework supports generating points fit for use, so you don't have to mess around with the Grid Framework API to get the vertices.
     
  28. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Grid Framework version 1.7.4 released

    Grid Framework version 1.7.4 has been approved by the Asset Store team. This release brings official support for Unity 5, so feel free to upgrade. Unity 4 is still supported, thanks to the changes to the Asset Store I can now upload separate packages for different versions of Unity.

    There are no API changes, so it doesn't matter whether you want to use Unity 4 or 5. The only real difference between packages are the example scenes. The formats Unity 5 uses are different from 4, so a package created in Unity 5 would appear broken in 4.
     
  29. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    Hi, I am going through the sliding puzzle example. Currently, the pieces snap into the nearest block. I want to change the behavior such that there is no snapping. So a grid block could be filled with 2 halves of 2 different blocks, or for that matter even 3. What is the best way to figure if the grid block is fully occupied with pieces, since now a piece falling in a grid block doesn't occupy the full block?

    ... if this is even possible efficiently.

    Thanks,
    Syed
     
    Last edited: Mar 2, 2015
  30. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Disabling snapping is easy: in the DragBlock scrip remove line 38:
    Code (csharp):
    1. SlidingPuzzleExample.mainGrid.AlignTransform(transform); // snap into position precisely
    figuring out how much of a block is now occupying a tile is more complicated... Let's see, assuming all block are multiples of the tile size we need to differentiate between odd and even multiples:

    [ even ]
    A block is two, four, six, and so on, tiles large. If it fits exactly, then the grid coordinates of the centre of the block are exactly between tiles, i.e. a whole integer number i.
    [ odd ]
    The centre is on a tile, i.e. it has coordinated i + 0.5.

    So find the deviation from this ideal and you know how much your block protrudes onto adjacent tiles. For example, assuming a three tiles large block has its centre at 2.7, we know that the ideal would be 2.5, so the deviation is 0.2. In other words, it occupies one fifth of the tile above and four fifths of the the tile below.

    Getting the ideal can be accomplished by running the `AlignVector3` method. The grid coordinates can be retrieved using `WorldToGrid`. Please refer to the manual for the exact API.
     
  31. sygaki786

    sygaki786

    Joined:
    Jan 26, 2014
    Posts:
    142
    Cool! Thanks!
     
  32. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    Your framework is amazing, I bought another one at the same time and it pales in comparison.

    So I'm working on a strategy game that has 3d maps. For example a floor with a stairway to the top of a castle wall is on the same map. Do you have recommendations on how I can have my grid correctly associate clicks on the stairwell and the top of the to their correct x/z coordinate? Essentially I guess I need to wrap my map with a grid. I'm working on trying to see if I can use the terran mesh generator example but I'm struggling so any assistance would be amazing.
     
  33. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    It looks like the terrain mesh example the collider mesh is being modified to the new shape. So perhaps I can somehow combine the colliders or modify the collider to be the shape of the map at the start.
     
  34. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Hi,

    You are right, the mesh is being modified: when the player clicks the collider the closest vertex is found, then raised be one grid unit up and then the resulting vertex is applied to the mesh.

    I don't know how your game works, but if the problem is clicking the grid the easiest solution would be to cover it with a mesh collider. The height of a vertex is the height of the underlying terrain. You will notice that I use a text-based height map in the example, that way I don't have to create the mesh manually. Every number in the file encodes three pieces of information: the X/Y position of the vertex mirrors the X/Y position in the file and the numeric value mirrors the height of the vertex. These three coordinates are then converted from grid- to world space for the mesh.

    Depending on how you store your maps you could do a similar thing where castle walls have a different height than ground floor tiles.

    It is important to understand that the grid itself has no "size", it is infinitely large in every dimension. So you don't wrap your grid around anything, you set the grid's properties and used the range and dimensions you want to use.
     
  35. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    Is there a way to make the grid slowly disappear starting from the top to give an effect the grid exists then slowly fades away from the top down?
     
  36. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Using an animation or coroutine on the grid's rendering range. Animations in Unity can do more than just make 3D models walk, they can animate any property on any object. The downside is that you must create them beforehand. Coroutines on the other hand can animate things programatically:
    http://docs.unity3d.com/Manual/Coroutines.html
    For example:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.     public GFGrid _grid;
    6.     public float  _speed = 0.01f;
    7.  
    8.     void Start () {
    9.         StartCoroutine(vanish());
    10.     }
    11.  
    12.     IEnumerator vanish() {
    13.         var startTime = Time.time; // the time when we started this coroutine
    14.         while (_grid.renderTo.y > _grid.renderFrom.y) {
    15.             var value = _grid.renderTo;
    16.             value.y -= _speed * (Time.time - startTime);
    17.             _grid.renderTo = value;
    18.             yield return null;
    19.         }
    20.     }
    21. }
    There is a more complex coroutine in the rotary dial example where the coroutine is used to animate the rotation of the dial.
     
  37. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    309
  38. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    No, it won't fit my design, Voronoi Grids are irregular finite-sized grids. All my grids are regular and infinitely large. Furthermore, an irregular grid would require some sort of input set, so the size of the grid in memory would grow with the input set, unlike my regular grids which only require a few float values.

    In fact, the proper term is Voronoi diagram, because it is not a real grid in a mathematical sense (a lattice graph) for the above reasons.
     
  39. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    One last question, I can't seem to get the grids to be visible in game view in anything but the provided examples. Everything is checked the same so it should render but nothing appears. Any idea why this would occur?
     
  40. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Have you added the Grid Render component to your camera? You can find it under Component -> Grid Framework -> Camera.
     
  41. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    That was it, thanks!
     
  42. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    Okay, I have one more question. Is it possible to render a grid that is not a simple square/rectangle using rectangle cells or should I just line up several grids to make more complex shapes?
     
  43. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Both, but the latter is easier. Have one invisible grid for your computations and have visible grids that don't do anything. If you are familiar with Unity's GL and Camera classes you can also use just one grid and issue the rendering directly calling the RenderGrid method. Take a look at the GFGridRenderCamera script (Plugins->Grid Framework -> Grid Rendering -> GFGridRenderCamera.cs) that you just added to your camera. It is very simple and you can use it as a template for your own script.

    Performance-wise it makes no difference, a grid that's invisible does not render anything. Memory-wise it is better to have only one grid, but grids don't take up much memory anyway. Flexibility-wise having one grid is better because you can call RenderGrid as many times in as many ways as you want.
     
  44. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    Can you explain the purpose of the invisible grid more? I think I understand everything else. Is the invisible grid supposed to block out the visible grid?
     
  45. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    I think you want to use a grid for calculations and stuff. If you only want the grid for visuals you don't need the invisible one. If you want to use the grid API you will want to have a reference to a grid and I would designate only one grid for the task with the other grids being just dummies for visualisation. Of course you could also use one of the visible grids as well. It's really just a matter of preference, I prefer for every object to do only one thing.
     
  46. astronaut

    astronaut

    Joined:
    Feb 25, 2015
    Posts:
    8
    Yeah, I'm only using the grid to make visuals easier. So I just need to figure out how to cut out portions of the visible grid to fit my board. Right now I'm stiching multiple grids together but id prefer to use 1 grid and pass in the shape information to the function to render.
     
  47. Krunchisoft

    Krunchisoft

    Joined:
    Jul 14, 2014
    Posts:
    22
    Hi there,
    Just bought your plugin.
    I tried to toggle playmaker action but it didn't work at all.
    Any suggestion ?

    Btw i'm using unity 5 and playmaker 1.7.8
     
  48. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    621
    Are you not seeing a message printed to the console that says "Enabled Playmaker actions for Grid Framework"? You can also toggle the actions manually, open the three script in Plugins -> Grid Framework -> Playmaker Actions and uncomment the following line:
    Code (csharp):
    1. //#definePLAYMAKER_PRESENT
    Uncommenting and commenting is what the menu item does as well.
     
  49. Krunchisoft

    Krunchisoft

    Joined:
    Jul 14, 2014
    Posts:
    22
    my console show nothing.
    but after taking out all the necessary comment everything it's working.
    so yeah.Thx a lot. :D
     
  50. Krunchisoft

    Krunchisoft

    Joined:
    Jul 14, 2014
    Posts:
    22
    Hi again,
    Sorry if i asking too much but is possible if you create like included example scene but using playmaker action ?
    i really really interested with the "movement with wall" example.
    Thx.
     
unityunity