Creating a grid from map model with obstacles

Hi, I have a simple tower defense map with the road is for the enemy (which is the player can’t build the tower there), and the other is for the tower can build there and with any obstacles (trees, rocks, etc)… However, i am not sure on how to make a grid (probably 2x2) loop through the map size and with differentiate with “red” for the obstacles and the road (I am thinking on using the Layer Mask to achieve this), and “white” for the tower can build there.

My map is like below (the red color is for the obstacles and the road, and the green color is for the tower that can build)

Image:

But the problem is, I can’t get it started and I am not sure where to start.

  • Create a grid (probably 2x2) loop through the map size.

  • Place a tower within the “white” color, and not “red” color.

Any idea on how to achieve this?

Your answer much appreciated.

Thanks

Ok so how exactly You want it to work? Cause there are some options:

  1. Randomly generated level where grid is build and path for enemies is created on the fly from one edge to another?
  2. Grid base layout for You to place all elements manually so it reduce level build time?
  3. Level is build based on color coded pixel map that You feed to the game?
    EDIT: 4. System that convert zero terminated string into gamefield?

Hi Bantaru, thanks for the reply, seems no 2 and 3 is good for me. But for the no 3, for example there are 2 maps other than the above map, do I have to make a path for it depending on the color that I chose? so that it can fit the criteria for no 3? Thanks :slight_smile:

When it comes to second option You can go to Edit > Snap Settings and set offsets of snap. Then You can move objects with Ctrl pressed and they will snap.

Third option is well complicated and requires a quite bit of coding. What You do is create a system that reads pixels of any type of image file. You code what color means what. So for example RGB 0,0,1 will be green square and 0,0,2 will be red. Then You create all maps in any image editor with color palet that You built into system. Feed those into Your game and system will read each pixel and convert it into object You attached to each color.

Here is great video explaining it:

Thanks for the help, will try to look on it. :slight_smile:

Why not use base grid line of unity?

Hi @herosf2006 , I’m quite new to Unity Engine, can provide me an example of what you are saying the base grid line of Unity?

Thanks

The gird line that is show up in Scene Screen, it easy to attach other models.