- Home /
Grid System (Unblock me) Unity3d
Hello everybody..
I am making "Unblock me" type of game. video : http://www.youtube.com/watch?v=2GQj6_J1Mxk I stuck at generation of grid system. As here cubes are moving in grid horizontally and vertically..
as well as cubes will be unit of 2-3 blocks of the grid. So stuck at making of such type of grid in whick i can make track of each block based on that cubes are allowed to move .
So please help me to make this system..
And if i am going to wrong track then also let me know.
Thanks all of you for your help and support in advance..
You really have a design discussion question at this point. There are many different way to approach this problem, and there are multiple issues here. Typically we suggest you ask a question on Unity Forums, but this is so nebulous that I think you would have a problem getting an answer there as well. Let me suggest how I might approach this problem. Note this just my ideas and another programmer might approach the problem differently (that is what makes it a design/discussion question):
I'd create my grid world on screen using units. That is, if you consider each block made up of two or more squares, I'd make each square 1 unit a side.
When not dragging, I'd have the center point of each square of each block be on a unit grid position (like (1,1) or (3,4)).
I would create a 2D array that indicates what positions are occupied. An array of boolean values would work, but I'd likely make it an array of references to blocks.
I would oversize the array by two rows and two columns. That is, if your game was 6 x 6 like Unblock $$anonymous$$e, the array would be 8 x 8. This would allow me to set the condition of the outside boundary. I would set all but one position around the edge as being occupied. The one not set would be the exit/goal. The use of these extra rows and columns would eli$$anonymous$$ate boundary conditions with my drag and drop code.
I'd likely align the array with my physical world. That is if you were creating a 6 x 6 game, the array would be 8 x 8 running from 0 to 7 in each dimension. The 0 and 7 rows/columns are the edges, so the grid point in the physical world would be 1 to 6 running from (1,1) in the lower left corner to (6,6) in the upper right.
With this setup, it is easy to snap squares to the grid when I release them from dragging (I'd only need to round the x,y position). It is also easy to map a squares central position to an entry in the 2D array. I could use $$anonymous$$athf.RoundToInt() for both x and y to give me back the indices into the array. This mapping is what allows me to limit the blocks movement.
Your answer
![](https://koobas.hobune.stream/wayback/20220613154106im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Issues with manual collision detection involving updates... 1 Answer
Grid snapping 0 Answers
Update Hex Grid Cell After Shooting 0 Answers