Search Unity

How to link objects to create a path for information flow

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

  1. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    Hi everyone. Asking this here since I'm making a top-down 2D game.

    If I knew how to better ask this question it's possible I wouldn't need to ask it so I'm going to take a stab at describing my scenario here.

    I am trying to determine the best way to have information flow along a path in the game. Imagine You are looking at a top-down cross section of a house. The walls would be thin, long rectangles and multiple 'walls' could be connected. Imagine one room has a power supply (circuit breaker panel, battery, whatever). The wall segments extend across the house to another room that has a load in it. A light bulb, a refrigerator, whatever; something that consumes the electricity.

    I want the player to be able to see, when everything is connected, a visual indication that electricity is flowing from the source to the load through a variable number of wall segments.

    Now, if one of those wall segments were to get destroyed, the flow of energy would stop. Unless there was another path, from end-to-end, through another set of wall segments.

    Now, imagine that it's not just electricity flowing from point A to point D but also water in pipes, through the wall segments, flowing from points B to E.

    I'm looking for a way (best way but any way) to orchestrate this in Unity.

    You may also be reminded of water and electricity flowing through systems in games like Sim City and that is similar to what I'm looking for except the paths of flow would be through dynamic objects.

    EDIT: It's actually very similar to this article--tho I'm not making a City Builder--but I'm looking for implementation details on how to build/manage the network.

    Thanks in advance for your help and feel free to call me names and make fun of me.
     
    Last edited: Mar 17, 2018
  2. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    Just giving this a one-time bump hoping for some guidance. Meanwhile I'll keep exploring... :/
     
  3. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    Sounds like you have two parts to tackle, modelling the flow and then displaying to the user. For the flow, you would start at the source of power and build a DAG, although this will depend on how true to reality your model needs to be. Once you have a DAG type model, pass this off to your render system. Here you could use objects with LineRenderer components. I have something similar in a couple of my projects with a simple shader that offsets a tiled alpha texture based on a time input so you can see a flow direction.
     
    BusyCat likes this.
  4. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    A DAG? My google-fu is failing...

    EDIT: I did find this after refining my search...


    EDIT2: I also found this non-Unity-specific article on implementing DAGs in C#. I'm writing tests and playing around now. https://msdn.microsoft.com/en-us/library/ms379574(v=vs.80).aspx#datastructures20_5_topic3
     
    Last edited: Mar 18, 2018
    furroy likes this.
  5. furroy

    furroy

    Joined:
    Feb 24, 2017
    Posts:
    93
    Sounds like you're on your way now. :)
     
    BusyCat likes this.
  6. BusyCat

    BusyCat

    Joined:
    Jan 9, 2015
    Posts:
    37
    Thanks for your help.