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. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    297
    I have defined a scale ( 2, 0, 1 ) to the AlignVector3, if I rotate it with adjusted scale ( 1, 0, 2 ), should it work or not ?
     
  2. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Looking at the screenshot and your description it should. Is it working for you?
     
  3. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    297
    just tested, it works. Thank a lot
     
  4. rscooke

    rscooke

    Joined:
    Feb 1, 2013
    Posts:
    4
    Hi Hiphish,
    I was wondering if you have any plans of connecting this Grid Framework to Playmaker at all? And if so a timeline on when it may be released.
     
  5. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I did in fact pick up a copy of Playmaker during a sale just for that ourpose, but I stilll haven't looked into it yet. It hasn't been on my priority list, but I might look into it after I get polar grids done.
     
  6. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    645
    I already made a bunch if you'd like to use them. There's 64 in total in the attached zip. I can't provide support for these though as I just don't have the time, sorry.

    My attached zip should get you started if you want to use them, modify them, sell them, I don't particularly care.

    I tried to follow the API structure and naming exactly. So should be relatively easy to use/understand after checking out the API documents. For example RectGrid/GFrmwrkRectGrid.cs lets you setup the full drawing of a Rect Grid; all the same options as if you used the component manually.
     

    Attached Files:

    Last edited: Jul 19, 2013
  7. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    This is a spectacular framework, but path finding seems almost essential to really make use of it in a game. I tried using an underlying NavMesh to accomodate but it's pretty messy. Have you successfully integrated any 3rd party path finding with this framework hiphish?

    Meh, I see this has been discussed already - ok i'll just add my voice to the path finding cacophony then :).
     
    Last edited: May 13, 2013
  8. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Don't worry, I hear you :) I want to finish polar grids first (it's progressing very well), then Playmaker support (shouldn't take too much time, since I just ned to hook up my framework to something else), and then I'll dive into pathfinding.
     
  9. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Polar Grid? Interesting ... be sure to allow for some way of sizing the center, i've been wanting to build talent trees in that vein ... I think TSW used something like I have in mind actually: http://i.imgur.com/5GmPg.jpg ... maybe not what you're shooting for supporting, but if possible go for it :) - having it return clicked "squares" would be awesome!
     
  10. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Here is a quick preview of the inspector panel, still WIP:
    [​IMG]

    There is two coordinate systems: the usual polar (technically cylindrical since we are in 3D) coordinate system and a grid coordinate system; the polar coordinate system works independently of the properties while the grid coordinate system is like a grid, just wrapped around itself, and is relative to the settings. The radius field lets you adjust how far apart the circles are and the sectors field sets how many sectors to divide the circles into. You can't set the angle manually, since we can only use angles that are fractions of 2π (or 360°), but you can always read the angle, either in radians or degrees. Depth sets how far apart the layers are and the plane is self-explanatory. The smoothness field is just there for drawing/rendering; I can only draw straight lines, so we add extra sectors to make the lines appear more smooth.

    And this is what that particular grid looks like in the end:
    [​IMG]

    You could then just set the radius and sectors to your liking and place your GUI elements on the faces. I know at least on user has already used grids for aligning GUI elements in NGUI.
     
  11. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,294
    Very Cool. Polar Grid Technologies is coming of Age.

    The addition of Polar Grid makes an already impressive GF even more Well-Rounded.

    Looking forward to the Release. Great work !
     
  12. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    This release serves as a preparation for Version 1.3.0, which will add polar grids

    • The methods NearestVertex/Face/BoxW and NearestVertex/Face/BoxG replace FindNearestVertex/Face/Box and GetVertex/Face/BoxCoordinates respectively. This is just a change in name, as the old nomencalture was confusing and makes no sense for grids with multiple coordinate systems, but the syntax stays the same. The old methods will throw compiler warnings but will still work fine. You can run a Search&Replace through your scripts to get rid of them.
    • The GFBoolVector3 class can now be instantiated via GFBoolVector3.True and GFBoolVector3.False to create an all-true or all-false vector
    • Similarly you use GFColorVector3.RGB, GFColorVector3.CMY and GFColorVector3.BGW for half-transparent standard colour vectors

    I apologize for the inconvenience of having to rename the methods, but I'll try to explain my reasoning. When Grid Framework was originally conceived only rectangular grids were in place. For rectangular grids only one coordinate system really makes sense, so there were two spaces: world space and grid space. Consequently, every point could only exist in either of those two.

    One of the most basic needs I implemented back then was to find the nearest vertex of a point, hence the name FindNearestVertex, and later the same for faces and boxes. I also needed a similar method for grid space, I wanted to get the point's grid coordinates.
    The problem arises when you start having more than just one grid space. When I wrote hex grids I always considered the possibility of having a second coordinate system aside from the herringbone pattern, and that's when I should have realized that my naming convention was... well, stupid. Polar grids will have two coordinate systems from the start, so I had the choice to either use some band-aid solution and have a naming convention that makes even less sense, or I could make a clean cut here and now.

    So, what does this mean for you? At the moment nothing aside from a bunch of compiler warnings. You can just ignore them if you want, the old methods are still in place, they just call the new ones instead. I don't have any intention of removing them anytime soon, so you don't need to rush ahead and replace your old calls. The syntax has stayed the same, so running a quick Search&Replace will fix things for good.
    The new naming convention goes as follows (without the brackets): Nearest[Vertex/Face/Box][X], where X stands for the coordinate system in question. For world it's W, for grid it's G and for the upcoming polar coordinates it will be P. Obviously only W and G make sense for all grids, the rest depends on the specific type of grid. You will be able to convert a point from any system into another (like PolarToWord).

    I am sincerely sorry for this, but please understand that this was a necessary step in order for Grid Framework to remain clean. I always find things to improve and tweak, but most of them are under the hood and go by unmentioned, it just happened that this one was on the surface.
     
  13. canozel

    canozel

    Joined:
    Oct 4, 2012
    Posts:
    3
    hi hiphish,
    i'm working on a kind of citybuilder game and i found your framework while surfing. But i have 2 Qs:
    1 - If i use this framework for my grid system , will my game be lagy because of framework(target platforms android and ios)?
    2 - I'm not sure of methods that framework include. Can you send a list of methods that are available in framework?

    Thanks,
    Cheers
     
  14. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    1) Several people have already released games for mobile platforms , so for a matter of fact it will not slow your game down, or at least not more than what would be absolutely necessary for the calculations to run. The size of your grid doesn't matter (aside from rendering of course), because al calculations are done locally, the actual grid (not the rendering) is infinitely large. The usual bottleneck for mobile games is always graphics and physics (including colliders), none of which Grid Framework is using.

    2) There are two PDFs included, one user manual and one scripting reference, you can find them in the Grid Framework folder of your project (unless you are using a pirated version, in which case please buy the product from the Asset Store, it includes all future updates for free, and report the site to me so I can take appropriate action)
     
  15. canozel

    canozel

    Joined:
    Oct 4, 2012
    Posts:
    3
    thanks for quick replay,
    i'm not using framework yet, i asked these questions to be sure before buying.I saw the matrix application in your puzzle game here, in forum, can i control my buildings in grids with that way? Finally, rotate them for 90 degrees and framework keep snaps in runtime?
     
  16. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Ah, I understand. I'll PM you the scripting reference and user manual so you can see for yourself.

    Snapping can be done simply by running
    Code (csharp):
    1.  
    2. var myGrid: GFGrid; // the grid we use for reference
    3. var myBuilding: Transform; // you building object
    4. myGrid.AlignTransform(myBuilding, false);
    5.  
    where false means the building won't pick up the rotation of the grid. You'll have to rotate objects yourself, that's easy enough using Unity's own API:
    Code (csharp):
    1.  
    2. // rotate counter-clockwise 90° around the Y-axis
    3. myBuilding.rotation += Quaternion.Euler(0, 90, 0);
    4.  
    The Aligning works by looking at your object's scale and then fitting it in your grid. To get runtime snapping you'd have to have to either align every frame while dragging or align once you stop dragging, whichever looks and feels nicer for you.
     
  17. canozel

    canozel

    Joined:
    Oct 4, 2012
    Posts:
    3
    Thanks for your attention man,
    i think i'll be around for new questions after buying framework.
    Cheers
     
  18. hantrax666

    hantrax666

    Joined:
    May 29, 2013
    Posts:
    5
    Hello, I downloaded and I can not seem to display a grid has the camera is in the game it is invisible your new version.
    I followed your tutorial soon as I left the lack this?

    sorry for pronunciation.
    thank you
     
  19. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Not sure what's going on from your description. In order to get a grid rendered during runtime you must create a grid by either
    • selecting an existing GameObject -> Component -> Grid Framework -> the grid type you want
    or
    • creating a new grid object from scratch by going to GameObject-> Create Grid -> the grid type you want

    Now you should be able to see the grid in the editor. To get it rendered in the game during runtime you must select your main camera -> Component -> Grid Framework -> GFGridRenderCamera. This script tells the camera to render the grid using Unity's GL class, a very low-level rendering class. This is necessary because the grid is not a mesh, that would be more expensive to render and less flexible.

    I just tested it with a new blank scene and it worked as it should. Note that it is possible to attach the grid component to the camera object, but the result will look weird, it's like sticking wires directly into your eye. If you want the grid to follow your camera it would be better to have a separete object for the grid and make it a child of the camera object. That way it follows the camera around and you have proper control over it. Also, make sure the grid#s renderGrid flag is set to true and that the hideAxis flags are set to false.
     
  20. hantrax666

    hantrax666

    Joined:
    May 29, 2013
    Posts:
    5
    thank you
     
  21. mweyna

    mweyna

    Joined:
    May 23, 2013
    Posts:
    13
    I'll start out saying my knowledge of programming is a bit new and limited.

    So I've been attempting to tweak the SnappingUnits.cs script to use X/Z with Y up, instead of the test scene which has Z up. However, whenever I try to do odd things happen. First and foremost the units do not maintain their original positioning, instead shifting on all axis and and lining up evenly on the Z axis. Additionally, pieces rotate 90 degrees (depending on the piece). Secondly, no triggers are created so they become unselectable and cannot be moved, as well as intersecting other pieces. Here is my tweaked "Snapping Units" script. Any thoughts as to why these issues are occuring?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class SnappingUnitsIan : MonoBehaviour {
    6.  
    7.     public GFGrid grid;
    8.    
    9.     public Material defaultMaterial;
    10.     public Material redMaterial;
    11.     private bool _intersecting;
    12.     public Vector3 hitPoint;
    13.    
    14.     private bool beingDragged;
    15.     private Vector3 oldPosition;
    16.        
    17.     //cache the transform for performance
    18.     private Transform cachedTransform;
    19.    
    20.     void Awake () {
    21.         cachedTransform = transform;
    22.        
    23.         //always make a sanity check
    24.         if(grid){
    25.             //perform an initial align and snap the objects to the bottom
    26.             grid.AlignTransform(cachedTransform);
    27.             cachedTransform.position = CalculateOffsetY();
    28.         }
    29.         //store the first safe position
    30.         oldPosition = cachedTransform.position;
    31.         // setup the rigidbody for collision and contsruct a trigger
    32.         SetupRigidbody();
    33.         ConstructTrigger();
    34.     }
    35.    
    36.     // these two methods toggle dragging
    37.     void OnMouseDown(){
    38.         beingDragged = true;
    39.         RaycastHit hit;
    40.         if (Physics.Raycast(ray, out hit))
    41.                 hitPoint = hit.point;
    42.                 print("We Hit at "+ hitPoint);
    43.     }
    44.    
    45.     void OnMouseUp(){
    46.         beingDragged = false;
    47.         cachedTransform.position = oldPosition;
    48.         _intersecting = false;
    49.         TintRed(_intersecting);
    50.     }
    51.    
    52.     // use FixedUpdate to allow colision detection to catch up with movement
    53.    
    54.     void FixedUpdate(){
    55.         if(beingDragged){
    56.             //store the position if it is safe
    57.             if(!_intersecting)
    58.                 oldPosition = cachedTransform.position;
    59.             DragObject();
    60.         }
    61.     }
    62.    
    63.     //this function gets called every frame while the object (its collider) is being dragged with the mouse
    64.     void DragObject(){
    65.         if(!grid)
    66.             return;
    67.        
    68.         //handle mouse input to convert it to world coordinates
    69.         Vector3 cursorWorldPoint = hitPoint;
    70.                        
    71.         //we want to keep the Y coordinate, so apply it directly to the new position
    72.         cursorWorldPoint.y = cachedTransform.position.y;
    73.        
    74.         //change the X and Z coordinates according to the cursor (the Y coordinate stays the same)
    75.         cachedTransform.position = cursorWorldPoint;
    76.        
    77.         //now align the obbject and snap it to the bottom.
    78.         grid.AlignTransform(cachedTransform);
    79.         cachedTransform.position = CalculateOffsetY();
    80.     }
    81.    
    82.     // makes the object snap to the bottom of the grid, respecting the grid's rotation
    83.     Vector3 CalculateOffsetY(){
    84.         //first store the objects position in grid coordinates
    85.         Vector3 gridPosition = grid.WorldToGrid(cachedTransform.position);
    86.         //then change only the y coordinate
    87.         gridPosition.y = -0.5f * cachedTransform.lossyScale.y;
    88.        
    89.         //convert the result back to world coordinates
    90.         return grid.GridToWorld(gridPosition);
    91.     }
    92.    
    93.     // this method will be called by the trigger
    94.     public void SetIntersecting(bool intersecting){
    95.         if(!beingDragged) // ignore sitting objects, only moving ones should respond
    96.             return;
    97.         _intersecting = intersecting;
    98.         //update the colour
    99.         TintRed(_intersecting);
    100.     }
    101.    
    102.     void TintRed(bool red){
    103.         if(red){
    104.             renderer.material = redMaterial;
    105.         } else{
    106.             renderer.material = defaultMaterial;
    107.         }
    108.     }
    109.    
    110.     private void SetupRigidbody(){
    111.         Rigidbody rb = rigidbody; //the rigidbody component of this object
    112.         if(!rb) // if there is no Rigidbody create a new one
    113.             rb = gameObject.AddComponent<Rigidbody>();
    114.         // non-kinematic to allow collision detection, no gravity and all rotations and movement frozen
    115.         rb.isKinematic=false;
    116.         rb.useGravity=false;
    117.         rb.constraints = RigidbodyConstraints.FreezeAll; //prevents physics from moving the object
    118.     }
    119.    
    120.     private void ConstructTrigger(){
    121.         GameObject go = new GameObject();
    122.         go.name = "IntersectionTriggerIan";
    123.         // attach it to the block and make it exactly the same, except slightly smaller
    124.         go.transform.parent = transform;
    125.         go.transform.localPosition = Vector3.zero; //exactly at the centre of the actual object
    126.         go.transform.localScale = 0.9f * Vector3.one; //slightly smaller than the actual object
    127.         go.transform.localRotation = Quaternion.identity;
    128.         // add the same type of collider as the block has and make it a trigger
    129.         Collider col = (Collider) go.AddComponent(collider.GetType());
    130.         col.isTrigger = true;
    131.         // attack the script to the collider and connect it to this script
    132.         IntersectionTriggerIan script = go.AddComponent<IntersectionTriggerIan>();
    133.         script.SetScript(this);
    134.     }
    135. }
    136.  
     
    Last edited: May 30, 2013
  22. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Let's get over your problems one by one:

    When something happens once the game loads always look for the Awake and Start methods, they are called once the script gets activated. In your case the culprits are the following lines:
    Code (csharp):
    1.  
    2.  void Awake () {
    3.     ...
    4.     if(grid){
    5.         //perform an initial align and snap the objects to the bottom
    6.         grid.AlignTransform(cachedTransform);
    7.         cachedTransform.position = CalculateOffsetY();
    8.     }
    9.     ...
    10. }
    11.  
    12. Vector3 CalculateOffsetY(){
    13.     ...
    14.     //then change only the y coordinate
    15.     gridPosition.y = -0.5f * cachedTransform.lossyScale.y;
    16.     ...
    17. }
    18.  
    AlignTransform does what the name implies, it aligns the object to the grid axes The idea is that if you have been placing objects by hand in the editor they don't necessarily align properly, so the script corrects that.
    The second line calls a method which sets the object's Y-position in the grid to half the unit's height. This time the idea is that you might have objects of different height (like houses and towers) and want them all to have their bottom on the "floor". Since you used a minus they are all "underground" with their ceiling touching the floor.

    If you don't whant that type of behaviour just comment away or delete those lines.

    AlignTransform rotates the Transfom so it has the same rotation as the grid. The first solution is not to rotate the grid and instead rotate the camera to your liking, the other one is to write
    Code (csharp):
    1.  
    2. grid.AlignTransform(cachedTransform, false);
    3.  
    The second flag means the Transform shall not be rotated.

    I copy-pasted your script, triggers do get created. Your problem is that your ray is hitting the object you want to move, which tells the script "move this object to where it currently is" or in other words: don't move this object. Your ray must hit something else, like a plane on your grid and pass through the object you want to move. You can use Physics.IgnoreCollision for that purpose
    http://docs.unity3d.com/Documentation/ScriptReference/Physics.IgnoreCollision.html

    To see what I man comment the following lines away:
    Code (csharp):
    1.  
    2. void DragObject(){
    3.     ...
    4.     //now align the obbject and snap it to the bottom.
    5.     grid.AlignTransform(cachedTransform);
    6.     cachedTransform.position = CalculateOffsetY();
    7. }
    8.  
    Now when you click an object it will move slightly but it won't move further until you click again. The reason it didn't move at all previously is because AlignTransform "corrected" the position after the first move.
     
  23. Landiron

    Landiron

    Joined:
    May 8, 2013
    Posts:
    5
    Greetings,

    1. I want to say thanks for this nice package,

    2. I got issues with it ;p

    I picked it up yesterday and tried to integrate the Runtime snapping example into my prototyping efforts, but failed to do so even after recreating it.

    For some reason that eludes me, as soon as hit the play button - my test boxes snap to Y = 0.5, and Z = -1, while retaining their correct X.

    Dragging them is not possible, instead of beeing dragged they just jump away when I click on them.

    The example itself works fine. But I'm getting the same issues in a complete new scene. - help would be appreciated ;)
     
    Last edited: Jun 6, 2013
  24. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    *sigh* I really shot myself in the foot with that example, it's what I get most questions about. I should see if I can make it better. Let's see, your first problem comes from the Awake method, it calls the CalculateOffsetZ method. The idea is that you have an XY-plane and sever abjects on it with different height, for example houses and towers. This method then takes half the object's height and sets the Y-position to it so the floor or the object is touching the plane.
    Code (csharp):
    1.  
    2. Vector3 CalculateOffsetZ(){
    3.     //first store the objects position in grid coordinates
    4.     Vector3 gridPosition = grid.WorldToGrid(cachedTransform.position);
    5.     //then change only the Z coordinate
    6.     gridPosition.z = -0.5f * cachedTransform.lossyScale.z
    7.     //convert the result back to world coordinates
    8.     return grid.GridToWorld(gridPosition);
    9. }
    10.  
    Since it's an XY-plane we use the Z-coordinate instead of the Y-coordinate. Another problem can be the way mouse input is being handled, it works only if the camera is not rotated. A better way of handling mouse input is to shoot a ray from the cursor and have it hit a plane (while making sure the ray cannot collide with anything but the plane, you don't want it colliding with your objects).

    I could answer your question better if I had more information on what you want to achieven and what your setup looks like.
     
  25. Landiron

    Landiron

    Joined:
    May 8, 2013
    Posts:
    5
    Thx for your time.

    Actually I dont want to achieve anything too fancy.

    Essentially, I have a pretty simple, flat terrain or plane (at the Y=0 level) on which I placed my grid, and want to place tile based objects on it that need to snap to the grid.


    My bad, but I just realized that the example seems to be for orthographic Camera only, which explains why I'm having issues getting it to work ;)
     
  26. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I am redoing the whole snapping thing for the next release because mouse input handling keeps confusing people. I'll PM you the new code.
     
  27. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    297
    [​IMG]

    I have a mesh combine with a number of square plane, is it possible to draw a outline around it using your framework ?
     
  28. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    You mean an L-shape out of the box like in your picture above? I'm afraid I can't do that, I only have rendering for grid-like shapes (a bunch of regular straight lines or haxagons and soon arcs as well). It looks like an ideal case for Vectrosity if you don't mind coding.
    http://starscenesoftware.com/vectrosity.html
    Vectrosity is a framework for rendering vector lines in Unity. The challenge will be in calculating the points for your vector line. Maybe Grid Framework could help in that regard but I don't know how your shapes are created. Sure, you could enter the values manually in grid space and then covert them to world space:
    Code (csharp):
    1.  
    2. Vector3 vertex;
    3. Vector3 linePoint = myGrid.GridToWorld(vertex);
    4.  
    That may be fine for small shapes, but for large shapes it would be tedious to enter it all. You could to something like this for each tile:
    Code (csharp):
    1.  
    2. Vector3 tile; // the tile in grid coordinates
    3. Vector3 vertexNE = myGrid.GridToWorld(tile + new Vector3(-0,5, 0.5,0);
    4. Vector3 vertexSE = myGrid.GridToWorld(tile + new Vector3(-0,5, -0.5,0);
    5. Vector3 vertexSW = myGrid.GridToWorld(tile + new Vector3(0,5, -0.5,0);
    6. Vector3 vertexNW = myGrid.GridToWorld(tile + new Vector3(0,5, 0.5,0);
    7.  
    but then you would have redundant vertices on you line where two tiles touch each other. Another problem will be sorting the vertices, you must pass them to Vectrosity in the order they appear on the line. How about instead of having one big outline you have four lines around every tile, but you can turn them off on a case-by-case basis:
    Code (csharp):
    1.  
    2. bool lineN;
    3. bool lineE;
    4. bool lineW;
    5. bool lineS;
    6.  
    The problem with this is that you are rendering more than you have to, if a shape is a hundred tiles wide you will have a hundred lines with two vertices each, resulting in 200 vertices instead of just two. It could be a problem for larger shapes, or it might not, you'd have to try. One last thing I could think of would be an "outline shader", some sort of shader that draws an outline on top of your entire shape. You might find something on the internet or ask someone who knows about shaders to make one for you. Maybe there is one here:
    http://wiki.unity3d.com/index.php/Shaders

    I hope this gives you some ideas, but I can't think of an out-of the-box solution. Outline shader sounds like the best idea to me, if you can find one.
     
    Last edited: Jun 7, 2013
  29. delphinius81

    delphinius81

    Joined:
    Mar 6, 2012
    Posts:
    38
    Any chance there will be support for creating grids that are not square shaped? I'd love to have a hexagon shaped grid of hexagons.
     
  30. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Hex grids were intruduced in version 1.2 and I'm about to add polar grids in the upcoming version 1.3. Is there something specific you are looking for?
     
  31. delphinius81

    delphinius81

    Joined:
    Mar 6, 2012
    Posts:
    38
    When you render the hex grid, it is arranged such that the hexes are drawn like:

    *****
    *****
    *****
    *****

    where each * is a hexagon.

    What I want to be able to do is draw the grid like this:

    Code (csharp):
    1.   ***
    2.  *****
    3. *******
    4.  *****
    5.   ***
    where again, each * represents a hexagon.
     
    Last edited: Jun 7, 2013
  32. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    A hexagon of hexagons. I know what you mean and it's on my to-do list. I hope I can get polar gids done by this weekend, then I can start extending hex grid support. The "problem" with hex grids is that there are many ways to do things and currently I'm only supporting a subset of them.
     
  33. delphinius81

    delphinius81

    Joined:
    Mar 6, 2012
    Posts:
    38
    Cool. After reading through the thread and watching videos, I picked up the package. Can't wait for pathing support in the future! With that, this package will be a must own for anyone looking to build grid based games.
     
  34. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    This is a really good framework. Work's really great. And with the "Seeming endless Grid" example I was able to have an "infinity" and high performance grid for smartphones.

    But one question. I can't get auto code completion to work in Visual Studio (C#). Any ideas?
     
  35. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Code completion works fine for me on Mac in both Unity Develop and Xamarin. There is an option in Unity called "Sync Mono Project", at least that's what it's called on Mac, I need to press to get auto complete in Xamarin, may you need that? Do you get auto-completion with other extensions? Usually the editor's auto-complete automatically picks up the API, I as the coder don't have to do anything.
     
  36. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    Hi hiphish. Sync the project and restart Unity/Visual Studio did it for me. Thanks!
     
  37. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    145
    Hi hiphish,

    Can we use Grid framework for ios android?
     
  38. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Of course, there is nothing exotic or platform-specific in my code, I do my best to keep it simple. Just three posts above you a user has written how he created the illusion of an infinitely large grid on smartphones without performance hit.
     
  39. lopez1de

    lopez1de

    Joined:
    May 22, 2013
    Posts:
    14
    Yeah, it's running smooth on Android (Nexus 4).
     
  40. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    145
    Thanks for the Info
     
  41. glebski

    glebski

    Joined:
    Nov 21, 2009
    Posts:
    367
    HI, Just bought the Grids and was trying to implement an isometric view of the grid and wondering if it's possible to make it "pixel perfect"?
    By this I mean to correspond to pixel dimensions of the game. For example if my player is 640x640, to have a grid that's 640 tall by 640 wide with divisions in x and y corresponding to each pixel, thus enabling pixel snapping for sprites etc. I have done it (sort of) with straight down orientation. Setting the camera to Orthographic, making W and H 640 and size 640 so (as far as I understand it one pixel = one world unit). But isometric is giving me imperfect results. Is there something I can try?
    $Screen Shot 2013-06-12 at 14.51.59.png
     
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I'm afraid it's mathematically imposssible to get perfect results converting pixels to world coordinates. Pixel-perfect means each pixel of the screen, which is a discreete (made from fixed points) rectangular 2D area. The world on the other hand is a continuous (free movements, not limited to specific points) 3D space that gets mapped onto the 2D surface. Consequently, no mapping will be perfect. It's like how when you want to draw a straight line at an angle on the screen the line will be jagged, the best the computer can do is add some smoothing blur to make it appear nicer.

    if you are using actual 2D sprites for an isometric look, as was done in old 2D games like SimCity, you are actually using an orthographic camera in principle. Of course there were no "cameras" back then, but the idea was the same: project some flat surface (sprite) onto another flat surface (screen). The game graphics were not actually isometric, they were just drawn to look isometric.

    Maybe I misunderstood you, but from what I understand you want to want to place objects in the 3D world and then position the camera accordingly. Right?
     
  43. glebski

    glebski

    Joined:
    Nov 21, 2009
    Posts:
    367
    Thanks for the reply hiphish. I guess I'm looking for a best case scenario. Whether I should pursue this isometric pixel look in unity or not.
    The screenshot shows what I'm after, but I need to get rid of the "artefacts" that do not fit the 2pixels across 1pixel up aesthetic of isometric pixel art. It seems to me that somehow if I manage to make one pixel = to one world unit and as long as all objects scale exactly by that "unit" and move by that "unit" then the look can be achieved... but then again, I am a bit of a novice. Cheers!
    $screen_shot.png
     
  44. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    Thanks for the screenshot, I now see. The thing you have to keep in mind is that Unity's world space is continuous, meaning any point in the world can have any coordinates, even a fraction of a unit, just like in real life (well, technically there are still limits because floating point numbers only have a certain range and precision, but let's keep it simple). A screen on the other hand is made of discrete pixels, there is no such thing as "half a pixel".

    You can find a good mapping that will map the continuous world points to discrete screen points, but there will always be case where the result of the mapping is not exactly what you want. Those are the bad conrners you are seeing. It even happens on the cubes, because the math itself is the problem.

    Imagine the following: you have a graphic with a certain size and you want to make it 1.5 times larger. If it's a vector graphic it's easy, just multiply all lengths with 1.5 and that's it. However, if you have a raster graphic (made from pixels) you can't just stretch it. You cannot make 1 pixel into one and a half, but making every pixel into two pixels is too much. In that case the somputer has to make a guess what the scaled image would look like, and the result may look good enough, but it's still just a guess.

    If you want real pixel-perfection I'm afraid the only thing you can do is actually draw it on screen through code. It's not impossible, but it kind of defeats the purpose of using such a high-level engine if you are going to put pixels on the screen yourself.

    EDIT: just as a reminder, the reason why you can get erfect-looking results for a straight-down view is that the grid happens to exactly fit the screen's pixels. That's a special case where the computer's guess is spot on.
     
    Last edited: Jun 13, 2013
  45. glebski

    glebski

    Joined:
    Nov 21, 2009
    Posts:
    367
    Thank you for such a thorough explanation. You should seriously consider writing books (if you don't already) about coding etc. Are you a teacher by any chance? Cheers.
     
  46. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    No, I'm not a teacher, but I do work as a private tutor part time to earn some extra money for my studies. I wouldn't be good at writing books about coding, there are people who know much more than me and have more experience. Me on the other hand, I'm mostly learning as I go along. There is nothing wrong with that, but you need more if you want to write a book.
     
  47. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    145
    Is Object to Object snapping is possible using this plugin ?
     
  48. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    You mean like things sticking to each other? I'm afraid that's outside the scope of grids. Of course you could fake it if your objects can fit in a grid (like in Minecraft), but sticking any object to any other object has nothing to do with grids and it wouldn't be a good idea to bloat the framework with unrelated features.
     
  49. achingupta87

    achingupta87

    Joined:
    Apr 9, 2012
    Posts:
    145
    Thanks Hiphish for your quick reply.

    Actually I need both type of snapping in my game. Grid Snapping Object to Object snapping(things sticking to each other).

    I think Grid snapping will be done through your framework. Can you please give me any idea how another type of snapping(Object to Object) will be possible? I will be great thankful for this.
     
  50. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    560
    I guess you could use a trigger that's slighly larger than the object are dragging. Once another object enters the trigger you make them snap together. You could finetune it by having one trigger for each direction instead of one large trigger in all directions, but that depends on the result you want to achieve.