Search Unity

2D grid with border objects

Discussion in '2D' started by ProfessorLizzard, Mar 15, 2018.

  1. ProfessorLizzard

    ProfessorLizzard

    Joined:
    Sep 7, 2017
    Posts:
    3
    Greetings everyone!

    I am working on a game, where every level is map of a mansion, composed of various Rooms. Each room contains a navigational grid, which is used by the AI to navigate between the various features and their hotspots, and it also stores adjacency data.

    In my first plan, all static features had the room they were in as their parent. But then I realized: what am I going to do with border objects, like walls and doors?

    Since I wish to make all walls and doors border objects, I can not set a room as their parent, since an object can have only one parent. Because of this, in an earlier attempt at map making, if I move a Room in my editor, the unparented walls stayed behind, forcing me to move them by hand. Perhaps I should make these walls generate automatically based on the navigational grid's adjacency data, deleting them and recreating them if a Room's navigational grid is edited, or if it is moved?

    Even if I use this regeneratative solution, it would still feel iffy that the walls have no parents. Perhaps the rooms scripts should contain a reference to the wall objects?

    Also note: walls also need to have colliders, so they can block line of sight.

    The following image is a mockup of what I am planning to do.



    I considered making walls and doors full tiled objects, as opposed to border objects, which would solve a lot of problems, would result in REALLY thick walls, which is more suitable for dungeons/forts, and not fitting for regular houses.
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    You can use several tile maps, with different tile size. That is, make the room/floor with one grid/tile size and then have another tile map on top of that with the walls. In the latter you use a much smaller grid/tile size.
     
  3. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    899
    Oh, yes the parenting problem. Make an empty object the parent of all the parts of the room. When you move it everything follows and it is easy to get at the other parts of the room from your code.
     
  4. ProfessorLizzard

    ProfessorLizzard

    Joined:
    Sep 7, 2017
    Posts:
    3
    A seperate tilemap could work probably, yes. I do have a new issue of the walls protruding into object that are on the main tilemap, but I guess I just need to keep in mind the possible border width while spriting them and/or setting up their colliders.

    I already do the gameobject parent, the issue is that the walls can be parented to both objects. Although, perhaps if a room is moved, I could temporarily parent the walls to it, and then unparent them after it was moved? Perhaps even leave behind duplicates of the walls, so the old room won't be walless.
     
  5. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    How about if you adopted a convention where each room only has a right and bottom wall. Then you can parent the walls/door to each room and if you shift rooms around you won't have issues. Along the top of and left side of the house. you make two empty rooms that just have walls on either left or top sides and place those along the edges.
     
  6. ProfessorLizzard

    ProfessorLizzard

    Joined:
    Sep 7, 2017
    Posts:
    3
    That could work! I would still need to update the adjacency data that way, but at least the walls would move without a hassle. Thank you!