Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Grid Framework [scripting and editor plugins]

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

  1. petrucio

    petrucio

    Joined:
    Aug 30, 2011
    Posts:
    126
    Yeah, reseting fixed it, thanks!
     
  2. heyitsalengsky

    heyitsalengsky

    Joined:
    Feb 18, 2014
    Posts:
    1
    Hi! Where can I get the Grid Plugin? Can I have it for free? I need it for my thesis. I am developing an Android Application. Please give me the Grid Plugin. Thanks! God bless!
     
  3. Trithilon

    Trithilon

    Joined:
    Aug 2, 2012
    Posts:
    30
    Hello I have a some feature Requests in order of Importance,

    Can you give us :

    1: Grid Pivot (This will essentially let you decide the exact size of the grid from the starting point you specify and help us know where to place it without trying to worry about the center of the grid too much) - VERY Important!

    2: Grid Direction/Flow (This will essentially let you control in which direction do the co-ordinates on your grid flow - Similar effect to rotating the grid)

    3: Limited Grids (Grids that will NOT be infinite, but rather respect their limits and will return the closest point on the grid)

    4: Cell Co-ordinates (Rather than grid junction co-ordinates you can get the center of a certain cell - so (1,1) will return a corner to NOT be the same as (1,1) which will return the CELL of the previously mentioned corner)

    5: Gridspace Offset (This can essentially solve the Cell Co-ordinates issues. This means - you can specify if the GridSpaceToWorldSpace will by default return)
     
  4. Trithilon

    Trithilon

    Joined:
    Aug 2, 2012
    Posts:
    30
    Hey buddy,
    AFAIK - Its a paid plugin. I have been following the author's work since almost the first version and I use it in every game I make now. Its useful and I feel its priced reasonably for the support, documentation, ease-of-use the robustness of it. I suggest you buy it honour the author's effort rather than putting him in an uncomfortable position. (I say this because I have been there)
    Trust me, you will not regret its utility! :) Just my two cents.

    Cheers!
     
  5. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Thank you for your kind words, Trithilon. I am currently in the process of finally finishing Playmaker support, there are still a few actions left to cover the base API (getting and setting values and invoking methods).
    I will reply to all your points.

    1) I'm not sure what exactly you are trying to accomplis with this. You can use the grid's renderFrom and renderTo if you don't like how the size is handled. Let's assume you want a grid that start at (0,0) and is 3 x 5 cells large. Let's also say we want each cell to be 1.5 x 2 world units wide. Then the grid will look like this (C# code, of course you also set all of these in the inspector)
    Code (csharp):
    1. GFRectGrid grid;
    2. grid.useCustomRenderRange = true;
    3. grid.renderFrom = new Vector3(0, 0, 0);
    4. grid.renderTo = new Vector3(3, 5, 0);
    5. grid.relativeSize = true;
    6. grid.spacing = new Vector3(1.5, 2, 1);
    7.  
    You have full control over where your grid starts and where it ends. If you look at the infinite grid example that's exactly what I do to create the illusion of an endless grid: using the camera's viewport I set the renderFrom and renderTo so it always just barely stretches beyond the view and when the camera moves I update the borders accordingly.

    2) I'm not sure if this would be worth effort if you can just invert the grid. It could be done, but the thing is that adding more code also adds to to maintenance overhead. Do you really need this feature? I think it would be easier to simply flip the grid's Transform by 180° around one axis; if the orientation of the Transform is important make the grid a child of it and rotate the child then. When I decided on the coordinate system I picked the directions Unity is using because it made sense to stick to the conventions of the parent framework.

    3) I'm sorry, but that is not possible, it goes against the very way that Grid Framework works. To get limited grids I would have to re-write the complete grid class. It would be easier to do the limitations within code, for example if you want to clamp a vector between a lower and upper bound you can write:
    Code (csharp):
    1.  
    2. public Vector3 ClampVector3 (Vector3 value, Vector3 lowerBound, Vector3 upperBound) {
    3.     return Vector3.Max( Vector3.Min( value, upperBound ), lowerBound );
    4. }
    5.  
    Thats the way I keep the boxes in the sliding puzzle example within the visible grid.

    4) This can easily be replicated using an extension method, just offset the grid coordinates by half a unit in X and Y:
    Code (csharp):
    1.  
    2. public Vector3 WorldToCell(GFRectGrid grid, Vector3 worldPoint) {
    3.     return grid.WorldToGrid(worldPoint) + new Vector3(0.5f, 0.5f, 0.0f);
    4. }
    5. public Vector3 CellToWorld(GFRectGrid grid, Vector3 cellPoint) {
    6.     return grid.GridToWorld(cellPoint - new Vector3(0.5f, 0.5f, 0.0f));
    7. }
    8.  
    9. public Vector3 GridToCell(GFRectGrid grid, Vector3 gridPoint) {
    10.     return gridPoint + new Vector3(0.5f, 0.5f, 0.0f);
    11. }
    12. public Vector3 CellToGrid(GFRectGrid grid, Vector3 cellPoint) {
    13.     return cellPoint - new Vector3(0.5f, 0.5f, 0.0f);
    14. }
    15.  
    Again like point 2), it's usually better for the user to implement these special-case methods, otherwise it ends up bloating the API for everyone even though most people will never have use for such a coordinate system. It's not just me who will have to do more work, but everyone else will have a harder time because if I include every possible special case the API will be so large to browse, it will be a pain. I have to decide what are the most useful and commonly used features are and design accordingly.

    There is a chapter on extension methods in the manual; once your extension method is written it will behave just as if it was part of Grid Framework from the start, it will even appear in auto-complete.

    5) Same as 4). Coordinate systems are basically just conversions from points; you have a point in one coordinate system (like world), then you convert it to the one you want to work in (like grid), do your calculations and if necessary convert back to world. The method I posted above is no hack or anything, it is the same way I do it for the various coordinate systems.

    Grid Framework is a paid product and available on the Asset store:
    https://www.assetstore.unity3d.com/#/content/4004
    I'm sorry, but I can't just go around giving free licenses, a lot of hard work and free time were spent creating this framework, and even when it is released my work is not done, I have to answer to customers and resolve issues as quickly as they arise. You will find that at the current price of 25$ Grid Framework is reasonably priced; it comes with a user manual, the full API documentation, source code, several use-case examples, free updates and of course customer support.
     
  6. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    641
    Hi Hiphish,

    My game is tile based, so the grid framework is just '2D' and only has 1 face.

    I want to have a gridface highlight when the mouse enters that grid (and then fade out on mouse exit) - can you give some advice on what the best way to go about this would be?

    In-case what I'm after isn't clear, here's a screeny of what I'm after - the white gridface being where the mouse would currently be located. Moving the mouse around would change which gridface is highlighted.

    $2014-02-22_1356.png
     
  7. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Hi,

    The way I would do it is first detect where in the world the mouse is pointing at and get the face coordinates. If the coordinates are about one times the grid's spacing apart we call the function for exiting tiles, store the new tile as our tile and call the function for entering tiles.
    Code (csharp):
    1.  
    2. GFRectGrid grid; // the grid itself
    3. Collider gridCollider; // some collider so the raycast can collide with it
    4. Vector3 tilePointedAt; // the tile we pointed at last (world coordinates)
    5. RaycastHit hit; // store the hit information here
    6.  
    7. void ShootRay() {
    8.     gridCollider.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit, Mathf.Infinity);
    9.     if (hit.collider) {
    10.         Vector3 newTile = grid.NearestFaceW(hit.point, GFGrid.GridPlane.XZ);
    11.         if ( Vector3.sqrMagnitude(newTile - tilePointedAt) > 0.9f * grid.spacing.x) {
    12.             OnExitTile();
    13.             tilePointedAt = newTile;
    14.             OnEnterTile();
    15.         }
    16.     }
    17. }
    18.  
    19. void OnExitTile() {
    20.     // your logic here
    21. }
    22. void OnEnterTile() {
    23.     // your logic here
    24. }
    25.  
    This is very similar to how the snapping in the Runtime Snapping example works. There I use the result of the raycast to find the nearest tile and use its coordinates as the object's position.
     
  8. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I just purchased this asset. I haven't even imported it yet. But I wanted to come here right away and say "+1 for PlayMaker actions". I know you are working on them so I wanted to show my interest.

    Thanks
     
  9. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I also wanted to make a suggestion that you add the words hex and hexagon to your products description in the asset store. I only found your asset by luck as I didn't find it when I searched the Asset store for those words.
     
  10. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    You're right, I never updated the tags. I'll have to do that when i release the next update. About Playmaker, I have covered nearly the complete API (getting and setting member variables and invoking methods), but there are a few special cases that are driving me insane. I think I'll just have an incomplete release first, there is no point in holding it back. Then I can try to figure the rest out.
     
  11. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Have you tried using the Playmaker forums? They are pretty good about providing help. And I **think** that they will provide special help if you are looking to support an existing asset -- like you are.
     
  12. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
  13. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Have you tried setting the "relative size" flag? Th size is measured in world units, and setting it makes the size measure relatively to the grid's own dimensions. And the size goes into both directions, i.e. fife units left and right. Yes, it was a dumb decision, it should be half the size in both directions, but now that the framework has been released like that I cannot change it without breaking people's existing code.

    That's not the issue, I am in contact with the Playmaker team and they are a great help. It's just that their API for extending is very rigid. Something simple like an enum, which is no problem in Unity, is impossible, instead i have to work around it using integers. Or custom classes like GFColorVector3 cannot be stored in FSM variables variables, I need to store the three separate bools and then assemble and re-assemble the bool vector in code.

    Their documentation is quite lacking as well, it doesn't have the nice verbosity as Unity's. If you just want to use Playmaker for building game logic it is a great asset and totally worth it, but extending it beyond the set expectations of the developers is a pain. But I can't complain about the help provided.
     
  14. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Ah! It is in world units. Now I see. And relative is in grids, but it is to each side and there is always on in the middle. This means there will always be an odd number.

    I would like to make a request that I am able to set the number of grids/hexes directly. So if I enter 20 x 20 I get 20 hexes in total length and 20 hexes in total width.

    As for Playmaker, I am glad you are making the effort. I think it will payoff for you in the long run by opening your asset up to a whole different market.

    And you probably already know about them but there are some extensions to Playmaker for Arrays and Hashtables (http://tinja.ws/1mw1Fro)

    I am also willing to be a beta tester for whatever you come up with.
     
  15. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    In your videos you often use a "debugger". I would like to use it myself, but I don't know how to get it working. Is there some documentation or can you make a quick video on this?

    Thanks
     
  16. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    That sounds just like renderFrom and renderTo: you set the lower and upper bound of your grid, like from (0, 0, 0) to (20, 20, 0) and that's what you get.

    Cool, I didn't know about that, but I don't need it either.

    There is a chapter called Debugging in the manual. Basically, there is a little sphere prefab in your project under Grid Framework/Debug. The documentation can be read from Unity's help menu under "Grid Framework Documentation", it's in HTML format and consists of a user manual and the API reference.
     
  17. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    That's what I needed. Thanks.

    I am off to RTFM. Thanks.
     
  18. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I RTFM and plopped a Debug Sphere down. I can get it working with finding the nearest whatever, but I cannot figure out how to get the WorldToGrid or GridToWorld working. Is there something extra I need to do?

    I am also uncertain as to what the Index is for. I defaults to three elements, but they don't seem to do anything.
     
  19. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    The debug sphere is mostly for internal purpose in debugging Grid Framework itself, but I left it in the distributed package, because it might come in handy for other people. To use World ToGrid and Grid ToWorld you have to toggle both the "Toggle Debugging" and "Print Logs" flags, then the result will be printed in the console. The GridToWorld debug function is kind of useless, it converts the sphere's world position into grid coordinates and back to world, but it can be used to detect discrepancies (if the code works properly there shouldn't be any discrepancy). The index variable I just checked, it doesn't do anything. It must be a leftover from something, and usually the compiler will issue a warning if a variable isn't used anywhere, but if the variable is exposed in the inspector Unity will suppress the warning, that's why I missed it.
     
  20. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    641
    Hi,

    Thanks very much for this, I'm trying to implement it now, but I'm getting a compile error that I've been unable to work out how to fix.

    I think this line:
    Code (csharp):
    1. Vector3 newTile = grid.NearestFaceW(hit.point, GFGrid.GridPlane.XZ);
    Is causing this issue:
    What confuses me greatly here, is the mention of the GA_Quality script - the two obviously aren't linked, and the GA script is a plugin I've imported.

    Are you able to help/ point me in the right direction here?
    Code (csharp):
    1. Internal compiler error. See the console log for more information. output was:Assets/GameAnalytics/Plugins/Framework/Scripts/GA_Quality.cs(101,24): warning CS0429: Unreachable expression code detected
    2.  
    3. Unhandled Exception: System.ArgumentException: Key duplication when adding: Vector3 NearestFaceW(Vector3, GridPlane, Boolean)
    4.  
    5.   at System.Collections.Hashtable.PutImpl (System.Object key, System.Object value, Boolean overwrite) [0x00000] in <filename unknown>:0
    6.  
    7.   at System.Collections.Hashtable.Add (System.Object key, System.Object value) [0x00000] in <filename unknown>:0
    8.  
    9.   at Mono.CSharp.MethodGroupExpr.OverloadResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Arguments Arguments, Boolean may_fail, Location loc) [0x00000] in <filename unknown>:0
    10.  
    11.   at Mono.CSharp.Invocation.DoResolveOverload (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    12.  
    13.   at Mono.CSharp.Invocation.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    14.  
    15.   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0
    16.  
    17.   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    18.  
    19.   at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    20.  
    21.   at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    22.  
    23.   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0
    24.  
    25.   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0
    26.  
    27.   at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
    28.  
    29.   at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
    30.  
    31.   at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
    32.  
    33.   at Mono.CSharp.If.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
    34.  
    35.   at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0
    36.  
    37.   at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0




     
  21. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Here is what might be important:
    According to the documentation the Hashtable class will throw an exception when trying to add an object with a key that's already in the table:
    http://msdn.microsoft.com/library/system.collections.hashtable(v=vs.110).aspx
    http://msdn.microsoft.com/en-US/library/system.collections.hashtable.add(v=vs.110).aspx
    http://msdn.microsoft.com/en-US/library/system.argumentexception(v=vs.110).aspx

    I don't know what exactly GA Script is doing with its hashtables, but maybe just renaming your variables could be enough?
     
  22. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    641
    Thanks again for the help, I've managed to fix it by doing the below - I think the GA script was unrelated, and that I was just confusing the two because it was in the same error message.

    I'm sure it's not tidy / efficient, but it works. Changing gridToHighlight.NearestFaceW to gridToHighlight.NearestFaceG got rid of the error. I do this in another script, which aren't linked together, not sure if that is what's causing the problem
    Code (csharp):
    1. gridFaceTransform.position = theGrid.NearestFaceW (targetPosition, floorPlane, false);
    Working :
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4.  
    5. public class GridHighlight : MonoBehaviour
    6. {
    7.     public GFRectGrid gridToHighlight; // the grid itself
    8.     Collider gridCollider; // some collider so the raycast can collide with it
    9.     Vector3 tilePointedAt; // the tile we pointed at last (world coordinates)
    10.     RaycastHit hitGrid; // store the hit information here
    11.  
    12.     public GameObject highlight;
    13.     GameObject highlightClone;
    14.  
    15.     // Use this for initialization
    16.     void Start ()
    17.     {
    18.         gridCollider = this.collider;
    19.  
    20.     }
    21.    
    22.     // Update is called once per frame
    23.     void Update ()
    24.     {
    25.         ShootRay ();
    26.     }
    27.    
    28.     void ShootRay()
    29.     {
    30.         gridCollider.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hitGrid, Mathf.Infinity);
    31.        
    32.         if (hitGrid.collider)
    33.         {
    34.             Vector3 newTile = gridToHighlight.NearestFaceG(hitGrid.point, GFGrid.GridPlane.XZ);
    35.            
    36.             if ( Vector3.SqrMagnitude(newTile - tilePointedAt) > 0.9f * gridToHighlight.spacing.x)
    37.             {
    38.                 OnExitTile();
    39.                 tilePointedAt = newTile;
    40.                 OnEnterTile();
    41.             }
    42.         }
    43.     }
    44.    
    45.     void OnExitTile()
    46.     {
    47.         // your logic here
    48.         Debug.Log ("Exited");
    49.         Destroy (highlightClone);
    50.     }
    51.    
    52.     void OnEnterTile()
    53.     {
    54.         // your logic here
    55.         Debug.Log ("Entered");
    56.         Vector3 tilePointedAtPos = new Vector3(tilePointedAt.x, gridToHighlight.transform.position.y, tilePointedAt.z);
    57.         highlightClone = Instantiate (highlight, tilePointedAtPos, transform.rotation) as GameObject;
    58.     }
    59. }
    60.  
     
  23. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    That's weird, when I try your script with NearestFaceW I get the same error. The weird part is that if there is an error in my code it should appear immediately when the method is defined, not when trying to call it. This type of error should appear only if I'm trying to define a function that is already defined. I worked around it by removing the default doDebug parameter value, instead the version that doesn't need doDebug is an overload.

    I will submit a fix, in the eantime you can replicate it by changing NearestFaceW in GFGrid.cs so the doDebug parameter has no default value. Add the following method after it:
    Code (csharp):
    1.  
    2. public Vector3 NearestFaceW(Vector3 worldPoint, GridPlane plane) {
    3.     return NearestFaceW (worldPoint, plane, false);
    4. }
    5.  
    The same odd behaviour happens with NearestVertexW and NearestBoxW as well. Thanks for bringing this to my attention.
     
  24. manders

    manders

    Joined:
    Mar 2, 2014
    Posts:
    1
    Noob question: is there some easy way to make a plane mesh that is the same size as my rect grid? I am following along with the realtime snapping video but I wanted to make a larger grid/mesh (more subdivisions) and don't see a way to do it.
     
  25. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Certainly, there is even an example for that:


    The Terrain Mesh Generation example uses the grid's coordinates to generate a mesh and a text file to decide on the position and height of vertices. You can strip away the parts that you don't need. For instance, if you only want a flat mesh ignore everything about string readers, leave the "height" coordinate of the mesh vertices the same and use the grid's size or renderFrom/renderTo to decide on the mesh's size.

    If you want a plane mesh that's made of only two triangle it's even easier, because you don't have to iterate over anything.
     
  26. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    641
    I didn't see this post until I saw the update in Unity, thanks very much for the excellent support. I've updated and changed to W from G and everything is still working exactly as I had before, with no errors!
     
  27. MikeTon

    MikeTon

    Joined:
    Jan 10, 2013
    Posts:
    57
    Works great now.

    Thanks for the advice hiphish.

    Loving the Grid Framework.

    -Mike

     
  28. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,352
    @Hiphish,

    Today I tried to export to IOS and got this message for the Terrain Mesh Example.

    Assets/Grid Framework/Examples/Terrain Mesh Generation/TerrainMeshBuilder.cs(186,22): error CS0103: The name `EditorApplication' does not exist in the current context
     
  29. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    That's to be expected, once you export to anything there is no `EditorApplication` anymore. The culprit is this little method:
    Code (csharp):
    1.  
    2. void OnDrawGizmos () {
    3.     if (!EditorApplication.isPlaying)
    4.         return;
    5.     Gizmos.color = Color.green;
    6.     Gizmos.DrawSphere(cursorPoint, 0.3f);
    7. }
    8.  
    It draws a little green gizmo sphere where your cursor is pointing above the terrain mesh. Since there is no editor application anymore the compiler has no idea what `EditorApplication.isPlaying` is supposed to mean, so it throws an error. It's for demonstration purpose only, o you just delete it before exporting or comment it out. Also, I really do not recommend to draw the wireframe terrain lines in the fashion I did, it tanks performance a lot. You should look into a better solution, I just used something quick dirty because it was not the focus of the example.
     
  30. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,352
    Ahh Ok,

    I saw it, now wrapping with:

    #if UNITY_EDITOR
    voidOnDrawGizmos () {
    if (!EditorApplication.isPlaying)
    return;
    Gizmos.color = Color.green;
    Gizmos.DrawSphere(cursorPoint, 0.3f);
    }
    #endif
     
    Last edited: Mar 9, 2014
  31. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Good idea, I'll wrap it up on my end as well.
     
  32. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
  33. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Sorry for the late reply, you are right. I'll issue an update, until then you can fix it by inserting `[SerializeField]` in the GFGrid class above _originOffset. It's line 135 of the file GFGrid.cs under Plugins/Grid Framework/Abstracts, and should look like this:
    Code (csharp):
    1.  
    2. [SerializeField]
    3. protected Vector3 _originOffset = Vector3.zero;
    4.  
     
  34. krishnamurthy

    krishnamurthy

    Joined:
    Mar 2, 2014
    Posts:
    1
    Hello!.. I was actually designing a game called Pulijudam also known as "Tigers and Goats" in unity. Right now I'm using GUI button to represent grid points but I don't think so thats a good idea, is there any other way to setup the grid ? How do you make each point in the grid accessible to the players ?
     
  35. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    I looked up Pulijudam on Wikipedia, with that few nodes it shouldn't matter much if you use GUI buttons. You will need to do profiling to find out if there is any real difference in performance.

    Anyway, if you won't want to use GUI buttons you can use a collider and raycasting. Place a collider onto your grid, then perform a raycast from the mouse cursor through the camera:
    Code (csharp):
    1.  
    2. GFPolarGrid grid; // I assume you want to use a polar grid
    3. Collider collider;
    4.  
    5. // call this when the player clicks
    6. Vector3 ShootRay () {
    7.     RaycastHit hit;
    8.     collider.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit, Mathf.Infinity);
    9.     //this is where the player's cursor is pointing towards (if nothing was hit return null)
    10.     return hit.collider != null ? hit.point : null;
    11. }
    12.  
    Now that we have the point we can find the nearest vertex. I assume you'll want your game mechanics to work in grid coordinates, but if you want polar coordinates simply change the G into a P or a W for world.
    Code (csharp):
    1.  
    2. Vector3 clickPoint = grid.NearestVertexG(ShootRay());
    3.  
    There is a small issue though: this will find the nearest vertex anywhere, even if the player clicks the collider somewhere far between vertices. You'll want only to accept input if the player's click was reasonably close to the vertex. Let's change the above code:
    Code (csharp):
    1.  
    2. const float tolerance = 0.2f;
    3. void validateClick(out Vector3 click) { // out means we pass the parameter by reference, not a copy
    4.     Vector3 gridPoint = grid.WorldToGrid(click);
    5.     click = grid.NearestVertexG(click);
    6.     if ((gridPoint - click).sqrMagnitude >= tolerance * tolerance) { // sqrMagnitude is faster than magnitude
    7.         click = null;
    8.     }
    9. }
    10.  
    11. Vector3 clickPoint = ShootRay();
    12. validateClick(clickPoint);
    13.  
    Another, simpler solution would be to use compound colliders: instead of one collider component add several children, each with their own little collider, one for each vertex of the playing field. unity will treat these colliders like one single collider of the parent object then. I don't know if there is a performance hit when using compound colliders, but you won't have to validate clicks anymore. There is some information on compound colliders here:
    http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html
     
  36. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I have found some odd behavior, possibly a bug.

    I have a working project that has the grid on the XY plane. I want it on the XZ plane. So I make the switch, but then my gridtoworld calculations are off my a factor of 1.75.

    I have made a video http://www.screencast.com/t/OhTiaX39

    I also have the project exported to a unitypackage. If it will help I can send the package to you.
     
  37. fieldrequired

    fieldrequired

    Joined:
    Feb 26, 2014
    Posts:
    108
    Hi, just purchased Grid Framework - I notice there is no documentation (as I would expect like a PDF or something) and no links to video tutorials.

    A little disappointed as I've no doubt there's documentation buried in there somewhere but there is no README.TXT file basically saying look here. I've managed to find the 3D grid that I'm looking for but the tricky part is that I want it distance culled (from an object) so that only set number of squares are visible if possible so it isn't infinitely repeating.

    Does anyone have any pointers? Or could point me towards anything that might get me started?
     
    Last edited: Mar 18, 2014
  38. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    There is a full user manual and API documentation in HTML format. You can find it in Unity's Help menu under Grid Framework Documentation. It made more sense to put it there rather than placing a readme file somewhere among the project's assets. Plus you have the source code available, but there shouldn't be any reason to have to dig though that. Finally, if you are using MonoDevelop and write in C# the documentation will show up in auto-complete.

    I'll take a look at it. If you could send me a Unity package that would help a lot; you can send it to me via PM if you don't want to do it in public.
    EDIT: are you using the latest version of Grid Framework? There was a fix for `CubicToWorld` recently in version 1.3.8, which also corrects all other methods that use it, including GridToWorld.
     
    Last edited: Mar 18, 2014
  39. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Yes, I am running v 1.3.8.
     
  40. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    I fail to see the problem. I imported your package into a new empty project, removed the "/1.75f" part and I get this:
    http://tinypic.com/r/mavwog/8
    The spheres are dead-centre. Am I missing something here? Did you mean something else? If I put the division back in the spheres are way off centre:
    http://i59.tinypic.com/doa1ef.png
    I only imported your package and didn't change or add anything else to the code.

    (using Unity 4.3.4 on OS X 10.9.2)
     
  41. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    What you are seeing is what I am seeing. However, that is not the issue. The spheres should line up with the underlying bitmap. If you remove the 1.75 factor, they are centered on hexes, but the spheres don't line up with the underlying bitmap.

    I will take the same unitypackage I sent you and change over to the XY plane and PM a link to you.

    Basically I am taking a worldtogrid for the underlying bitmap (heightmap) and then assigning the average to an array matching the grids. Then I do a gridstoworld on the array.

    Stand by for the other package.
     
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Your variables i and j are integers, so it is only natural that your spheres will be as they are, on the centre of the face of a hex. When I print i and j the numbers do match up with what I see, so the grid-to-world conversion is working as it should. I don't know what your algorithm is supposed to do, but this part is working as it should.
     
  43. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    @hiphish,

    I discovered where my error lies. I was not changing one variable from y to z when I rotated the grid. Thus my calculations were off. I apologize for wasting your time on my bug.
     
    Last edited: Mar 19, 2014
  44. ageana

    ageana

    Joined:
    Nov 6, 2013
    Posts:
    23
    Any idea why Unity freezes when I import the package? I have to force exit to restart it, and I have no idea if the package is imported completely.
     
  45. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I haven't had any problems. Were you attempting to import into an existing project? If so, try a new empty project and then import. That will narrow down the issue at least. I also assume you are using the latest versions of Unity and the Grid Framework.
     
  46. ageana

    ageana

    Joined:
    Nov 6, 2013
    Posts:
    23
    You are right. When I imported it in a new/empty project it worked well. I managed to import it in my existing project by importing it twice (importing it again after restarting unity). I hope that's ok.
     
    Last edited: Mar 19, 2014
  47. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Importing twice is no problem, already existing files will simply be overwritten.
     
  48. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Origin Offset keeps resetting back to 0. I've set Y to -30 and Z to -0.51 yet it refuses to keep it. Soon as I hit play it resets to 0. I need to be able to offset because my tile system goes down instead of up and I want the grid to be slightly further out than my tile system, which looks great in editor until I press play.
     
    Last edited: Mar 23, 2014
  49. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    610
    Hi, someone has had the same issue a few post above. You can use this solution until the update goes live:
     
  50. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    That seams to have worked, thank you!
     
unityunity