Search Unity

How to check if player made room has no holes

Discussion in 'Scripting' started by ArtLove, Apr 19, 2015.

  1. ArtLove

    ArtLove

    Joined:
    Oct 16, 2012
    Posts:
    49
    Good evening!

    So lets say we have two 3-dimensional rooms made of 1x1x1 cubes. One room is in the shape of a box while the other is a 3D "L". Both rooms have walls, floors, and a ceiling. How would one go about checking each structure within the game, by code, to see if there are no gaps within the structure?

    What if these structures were connect like so: L[ ]. How would we determine that these are two separate structures/regions and place them in their own empty parent game object? I intend these empty objects to be named "region" and will combine regions if the wall blocking both structures was deleted.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I haven't tried this before, but here is the approach I would take.

    Define some arbitrary point that is definelty outside. Set up a network of nodes using ray casting. Use a graph traversal technique like Dijkstra to find all visit able nodes from your indoor start position. If the outside node is visitable, then the room is not closed.
     
  3. ArtLove

    ArtLove

    Joined:
    Oct 16, 2012
    Posts:
    49
    Definitely an interesting technique, BoredMormon. I am trying to think of a way to determine the point to use that is definitely on the outside of the room. These rooms could be made of all one object and in open space. So there is no grass or floors in which one could use for said point.

    I then would have to place that room as the child of a different object.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Is the total space limited? If so you could start outside and try to get in. If you can get to every node then nothing is enclosed.
     
  5. ArtLove

    ArtLove

    Joined:
    Oct 16, 2012
    Posts:
    49
    The total space is "unlimited". You can start building anywhere (x, y, or z) and build 3-dimensional buildings of any shape. I've been writing different methods down that are inefficient. I'll see what I can do with yours.
     
  6. ArtLove

    ArtLove

    Joined:
    Oct 16, 2012
    Posts:
    49
    I'm thinking about just allowing players to build on the 1-y axis and anywhere within x and z. Therefore, I could fill the 1-y with cubes that monitor room closures. I cannot use this method with infinite-y as it'd take forever just to place these cubes at runtime.