- Home /
Tracking ojects grid positon
So Recently I have been trying to figure out how I would go about putting together a rudimentary puzzle game system inside of Unity. Something based in blocks of a static size and shape. What I arrived at was that I should create a 2D gird using a 2D array that could then store the positions of all of the various puzzle objects in the grid. That would be easy to loop through and check for matches and etc. My biggest question is really how I would go about tracking the position of the puzzle objects inside that array!
I was also wondering about the "best" way to go about establishing that 2 dimensional grid. This question is sort of broad. Please ask away in the comments if you need me to expand on anything here. Thanks a lot for the help!
Nailing down an approach will depend on the details. A reference to a similar game would be very helpful. How does your game relate to these where all the blocks are square, same size and do not rotate?:
Answer by programmrzinc · Oct 01, 2013 at 08:38 PM
hmmm. What i would do is scale the 'grid' based on real world positions.
Like if a 1 unit cube is at 0,0 in your game, the real coordinates would be at
Vector3(0.5f,0.5f, 0)
That way, all you need to do is pass the coordinates through a function to extract the game coordinates from the real word position
void GetPos(GameObject tempGO){
Vector3 gameLoc;
gameLoc = new Vector3(tempGO.position.x - 0.5f, tempGO.position.y - 0.5f, 0);
//Assign gameLoc to a public variable to use.
}
Your answer
Follow this Question
Related Questions
2d Array persists during multiple game sessions 2 Answers
2D Array of GameObjects... 1 Answer
Determining groups in a 2D array by checking neighbours (and their neighbours etc) 2 Answers
I'm having trouble with grids and instantiating arrays of prefabs. 1 Answer
Using a list of arrays to make Unity UI 2D button toggle colors 0 Answers