0
votes

I'm a complete noob in gamedev, but I've watched a number of videos on generating a 2D array to setup Grid-based combat (pathing, obstacles etc), and I don't find the programmable approach intuitive or visually friendly.

Is it possible to setup such level with obstacles using multiple tilemaps?

  • 1st tilemap would include the whole level zone (I named it "General Tilemap"): General Tilemap
  • 2nd tilemap would only contain tiles that would be marked as collision when being read (I named it "Collision Tilemap") and player wouldn't be able to move to them: Collision Tilemap

My logic would be to read the adjacent tiles around the player, and if:

  1. A tile exists on the General tilemap, but not on the Collision tilemap, player can click it and move there.
  2. A tile exists on both tilemaps, it is marked as collision, it cannot be clicked.
  3. A tile doesn't exist, it is out of boundaries, it cannot be clicked.

Could you please let me know if this is a valid approach (for smaller levels at least, I won't be making anything large so scalability is not an issue), or have I gone completely off course and there's a superior way to do this properly? I'm currently stuck at the very first step - reading whether the tile on a coordinate (next to player) is existing or null for both tilemaps. Doing my best to figure it out though.

Thanks!

1

1 Answers

0
votes

Managed to check if tilemap contains a tile on xy coordinates in Start function, by finding the relevant Tilemap and using hasTile to read it it has value or not. This returns a boolean.

Tilemap generalTilemap = GameObject.Find("General Tilemap").GetComponent<Tilemap>();
hasGTile = generalTilemap.HasTile(playerTileCoord);

Still not sure if this approach will work for me long-term, especially when I get to the pathfinding algorithm, but we'll see!