- Home /
Best way to keep track of objects on a 3D Grid?
I'm looking for a good way to keep track of objects on a 3d grid. For example, I want to query a point at say: (0,0,0) and find out if there are objects on any of its 4 "corner" points on the X/Z grid plane. (These would be (1,0,1) ; (1,0,-1); (-1,0,1); and (-1,0,-1)).
Note these would be custom grid coordinates, not transform.position values per se.
I was thinking a good way to do this might be a multidemensional transform array of some sort, but since array's can't take negative values I probably can't store the relevant grid-position data there.
Any help to get me started is appreciated!
Answer by Jesse_Pixelsmith · May 30, 2014 at 01:23 PM
I've actually found a solution using:
Dictionary
, which was pretty easy once I got some sleep :)
Thank you though!
Could you share your Dictionary structure? I'm building a 3d Tetris type game and I need to know where the dang blocks are at any given time, it's beco$$anonymous$$g a pain!
Answer by Clet_ · May 29, 2014 at 11:23 PM
You should use multi-dimensional array. You can't access negative positions, which is the correct behaviour, but you could implement a function that takes a Vector3 as input, find the appropriate array indices and return the object at that position in the array.
If you have the center (or one of the corner) of your grid, the column/row count and the width/height of each "square" in your grid, it is relatively easy to do this.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Failed setting triangles in my mesh 1 Answer
Vector3 resultant array sorting 2 Answers