Hi EscapeTheFate0921,
I do lots of 2D Grid work for procedural generated Roomsand Dungeons. I use them in my current Dungeon Crawler. There are many ways to approach this. Firstly, I would anticipate using some method to store Grid Cell location Names. Secondly, a form collision detection/calculation between player and Grid Cell.
A good place to start is with the Grid or Matrix itself. A 2D Grid has X,Y Planes. You can divide these up Rows and Columns to create Cells, then its simple math to calculate player location in relation to cells dimension or group of cells. The player is located in Cell[3,1] to move we use these simple formula to move n cells.
[FONT=courier new]
X = Horizontal[FONT=courier new]|Column, Y = Vertical[FONT=courier new]|Row
North = [FONT=courier new]X, Y-n
South = [FONT=courier new]X, Y+n
East = [FONT=courier new]X+n, Y
West = [FONT=courier new]X-n, Y
[TABLE=“class: grid”]
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
The following formulas can provide the basis for setting up the collision detection/calculation between player vs grid cell and should provide player positioning mechanism. For simplicity we assume each Cell is equivalent in size width and depth. We can calculate the Cells location in 3D space based on its column and row in the Grid, [FONT=courier new]Cell[column,row] Multi-dim to Linear Conversion: [FONT=courier new]Column * Max.Row + Row. In 3D Space the cell location vector {x,y,z} can be calculated by [FONT=courier new]cell.location = {cell.width * column, [FONT=courier new]cell.depth * row, 0}
Using arbitrary value for width = 50, depth=50, we can calculate the location of the player in relation to the Cell. So if the Player is location 135,51,100 we can divide x/width, y/depth, z0(not used) for 135/50, 51/50, 1000 → 3,1,0 → Cell[Column=3, Row=1]