Grid based pipe system problem

Okay so sorry if I cannot explain my qestion properly. But i have a pile of pipe models, they can be placed in game on a snap to grid system. I Have made them all slightly larger so they can all collide with each other. No i have a start cube, and a destination cube. I Need to make it so that if there is a piper going from the start cube to the end cube the end cube knows that. so basicly. if there is a complete link in the pipes from start cube the end cube, end cube can be like, oh yes now i can send items to you. Sorry if you dont get what I mean but how can I do this. I Have been at it for about an hour.

You will not be able to solve this without some sort of “path-searching” algorithm. Just the collisions alone won’t get you to the end. So if you are new to programming in general, it gonna be tough.

Many path searching algorithms work on “node graphs”. That means basically that every pipe section has a list of only connected neighbouring sections. Then the algorithm tells you, whether there is a path from any specific node to any specific other node (and sometimes the shortest path in case there are multiple). You can use the fact that your pipe sections collide with each other to easier store whether they are connected.


However… if you are really only interested in a “is there a connection or not?” then the absolutely most simplest algorithm I could ever think of is this (assuming your pipes are tagged with “pipe”) using the Physics.OverlapSphere:

HashSet<PipeConnection> connected = new HashSet<PipeConnection>();
connected.Add(startPipe);
again:
foreach (var c in connected)
    foreach (var s in Physics.OverlapSphere(c.transform.position, slightlyLargerRadiusOfYourPipe))
        if (connected.Add(s))
            goto again;
if (connected.Contains(endPipe))
{
    // we got a connection! Horay!
}

This code is utterly ugly and inperformant. Have a nice day. :smiley: