Implementing a Square Grid Map

I am a beginner to Unity3D and 3D game development in general. However I would like to implement a simple grid based game (similar to chess). What is the right way to do this? What if the map is not flat and if some grid cells have different heights? What if the entire map is not square like a chess board, but rather an irregular shape? Would it be better to use an external 3D modelling software to create the map or would it be better to just use Unity3D’s own terrain? How would I ensure that the grid is always visible to the players since I am not interested in colouring each grid square black and white.

Think it would be better to model the board using an external modelling tool.

I thought that seemed like the right thing to do too. But how would the grid work? Would I just create an invisible mesh on top of the board?

I’d make the board as a Mesh. No need to have anything invisible.

So you are saying import the mesh from another program and then apply a collider to that mesh to use as the board right? When I am doing this, would I just round of the coordinates from a ray cast to get discrete grid squares to move to?

I’ve changed my mind. I would use the Mesh API in Unity to create the hex board in code. I’d put the hex tiles in the xz plane, with y=0. Since I know where the tiles are in space, there is no need to use collisions or ray casts to work out where the players are.

Create a hex tile with radius 1, centred at (0,0,0). Vertices will be (1,0,0), (0.5,0,1), (-0.5,0,1), (-1,0,0), (-0.5,0,-1), (0.5,0,-1). Then place a copy at (0,0,2). Then one at (1.5,0,1) and another at (1.5,0,-1) and so on. You can place as many tiles as you want in this way.

So what you are saying now is to import a pretty board model and then have a mesh overlayed on top with the actual grid mesh(I am using square grids). What is the advantage to doing this? Also would I not need collision detection and ray casts to figure out which tile the player has clicked on?

No, I am saying create the tiles/board in code.

(I am having a bad evening… I’ve been talking about a hex mesh because I was reading a very similar thread about a hex tile board. Creating square tiles and placing them is of course easy.)

If I make the tiles in code, how would I make the board look better. For example if I wanted to apply a graveyard theme or forest theme to the board. I am imagining sort of like a clearing in a graveyard with a grid overlayed aesthetic. Also how would I get user clicks without raycasts and colliders?

Well, if you want fantastic artwork, then maybe do it externally in a modelling package. Then use ray casting.

Doing it this way makes a lot of sense to me since the programers can work on the code and the artist can work on the aesthetic of the game board. However with something like this, how would you be able to highlight specific grid squares say with a blue highlight or a red highlight for when the player selects particular grids. Also the visual part of the grid (actual grid lines) would have to be part of the texture in the imported model right?

I know this reply comes a bit late, but as this thread is the first google result for “unity square boards on terrain”, I will provide my current solution if the board is not flat and not periodic (e.g. chessboard with random mountains).

  • place pieces on dots instead of tiles, dots being the intersection of lines (e.g. go/weiqi/baduk)
  • every dot will be represented by an empty GameObject
  • as all dots have a specific distance from every other dot in x, z direction you can use this information to to get adjacent dots by searching for them in the area (e.g. Physics.OverlapBox), where they should be (e.g. 1 unit away from the searching dot in x direction, y direction being the maximum height a unit can traverse between adjacent dots)
  • create a graph with nodes representing the dots and edges representing movement options between dots

Hi!

My name is Carol, I’m from brazil.

I’m doing an university work and I need to join a Grid in a Map.

Can someone help me?

Tks