Hello,
i’ve a questione about game grid. I want to create a game grid for a chess game (for example), so i need a plane composed by a set of Cells. For example 10x10. So, when i click on my plane, i need to take my cell coordinate… For example, if i’ve clicked on a specific place of plane, i will get “x: 1, y: 2”.
How can i make it? I’ve no problems with raycast and objects selection, but now the point is: create a game grid to translate my Pawns on it.
You could create each cell as a Game Object (a plane, for example) and create white and black textures. Then, arrange the cell positions and textures like a chess board.
If you know how to use raycast, then you can easily determine which cell (plane) your mouse is over…
Not necessarily. As far as detecting which grid field is currently under mouse, you could have just a single plane (or rather, a thin box collider) and calculate grid coordinates out of hitpoint coordinates.
I agree. A chess board grid would be easier done using a single textured plane (or more complicated mesh, if you so wish), imo. Less hassle and less polygons
For a simple textured plane, I would check the UV coordinate of the impact point. Since a chess board has 8x8 pieces, then the hit grid would be (in pseudocode)
x = Mathf.Floor(u / 0.125)
y = Mathf.Floor(v / 0.125)