Search Unity

Smartest approach to figure out if ship was divided into parts.

Discussion in 'Scripting' started by Chesiqcom, Sep 16, 2017.

  1. Chesiqcom

    Chesiqcom

    Joined:
    Dec 19, 2015
    Posts:
    2
    I'm making a 2D game where player can build a spaceship out of predefined blocks.
    Ship has physics, thrusters etc..

    I'm using a 2D matrix to store all data of the ship.

    Player can build blocks that add data to data matrix for further calculations(oxygen, rooms.. etc)

    Blocks can be destroyed, and the question arises:

    How to determine a ship chunk? (In the nicest in terms of performance way)
    here is what I'm talking about in form of a video:


    Of course I can determine that each part of floor is connected via another part of floor and so on and at time of destruction re check every block(performance hello) is connected to some other "important" block and then find out that this blocks are not connected to that blocks - delete part of ship - recreate it at same location.. but maybe there is a better approach?

    i was thinking to destroy the chunk blown off but that's just so game breaking - imagine a big station having just 1 tiny pass way connecting 2 big parts and if that's blown up - a whole half of station gets blown up.

    I tried searching but I just cannot formulate the query to get anything remotely to what I'm talking about.

    If anyone has any ideas, would really help me out or just a link would be awesome.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You're trying to find all distinct connected subgraphs of a graph. Here's an SO page about exactly that; the top answer is exactly how I would do it.
     
    Chesiqcom likes this.
  3. Chesiqcom

    Chesiqcom

    Joined:
    Dec 19, 2015
    Posts:
    2
    Thank you!
    As a programmer without proper education, I can only overcome programming thingies with perseverance. And this one would take me something around pfff.. at best 3 days of headache, drawing in photoshop diagrams and different schemes.. sleeping with matrix visions.. basically I would logically reinvent flood fill algorithm in a bizarre un-optimized way..

    You saved me there.

    Exactly what I was looking for.

    Thank you.

    I have 2d matrix with data and placeable floors and walls and stuff that can be 1x-16x dimensions of a single cell, so I can flood fill just the objects(store in them their peers) without filling my giant matrix.. Beautiful!
     
    Last edited: Sep 16, 2017
    JoeStrout likes this.