Search Unity

Checking if gameObject is connected to another gameObject? (think powergrid)

Discussion in 'Scripting' started by notoriousnary, Feb 13, 2016.

  1. notoriousnary

    notoriousnary

    Joined:
    Jul 16, 2015
    Posts:
    9
    Hi all,

    I'm working on a project that involves building a base and I am struggling with trying to check if the bases modules are all connected. I've managed to work out how to get the modules to "snap" to attachment points but this part is really racking my brain at the moment.

    Base layout in unity is as follows (Screenshot Attached)



    BaseHub (Nerve Center) > AttachmentPoint > "rest of module" > AttachmentPoint


    Since the baseHub is going to have a fixed number of attachment points I'm testing if i can store a reference to the modules connected to the hub and the gameObject each attachment point connected to then using a raycast and seeing if it hits the same object but I can see errors potentially occuring if the ray is in a movable section etc along with I don't know how big the Performance impact of continually sending out rays and checking this on each module would be.

    My google-fu seems to be failling me recently so if anyone has any suggestions even just a pointer in the right direction would be appreciated.
     
  2. notoriousnary

    notoriousnary

    Joined:
    Jul 16, 2015
    Posts:
    9
    I think I may have worked out a solution (working on the projects AI) basically it seems that I'm trying to do a form of Pathfinding without a navmesh since I just need to know if a module has a route to the hub/power source etc. I'm working on that code tomorrow and I'll make sure to post it for others once its done ^_^