Search Unity

Creating a grid from map model with obstacles

Discussion in 'Scripting' started by Fuhans950, Mar 26, 2017.

  1. Fuhans950

    Fuhans950

    Joined:
    Mar 26, 2017
    Posts:
    4
    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:
    90677-map.png

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

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

    2. Place a tower within the "white" color, and not "red" color.
    Any idea on how to achieve this?

    Your answer much appreciated.

    Thanks
     
  2. Bantaru

    Bantaru

    Joined:
    May 11, 2016
    Posts:
    59
    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?
     
  3. Fuhans950

    Fuhans950

    Joined:
    Mar 26, 2017
    Posts:
    4
    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 :)
     
  4. Bantaru

    Bantaru

    Joined:
    May 11, 2016
    Posts:
    59
    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:
     
  5. Fuhans950

    Fuhans950

    Joined:
    Mar 26, 2017
    Posts:
    4
    Thanks for the help, will try to look on it. :)
     
  6. herosf2006

    herosf2006

    Joined:
    Nov 9, 2016
    Posts:
    4
    Why not use base grid line of unity?
     
  7. Fuhans950

    Fuhans950

    Joined:
    Mar 26, 2017
    Posts:
    4
    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
     
  8. herosf2006

    herosf2006

    Joined:
    Nov 9, 2016
    Posts:
    4
    The gird line that is show up in Scene Screen, it easy to attach other models.