As you can see from the image above. there are two machines and a pipe connecting them, the pipe is made of induvidual peces as they can be placed by th user. I Have a problem where I cannot figure a way to make the two machines knwot hey are connect.
Lets say on the frist machine there is a function saying, if the pip it is touching is linked with the machine they can interact, but the problem is making all the pipes know if trhey are or not connect to what machines. Any ideas, Thanks
Typically this would be done by traversing the network to see if a connection can be made.
Two strategies I see for this
Frequently send a ‘ping’ from each piece of equipment. Each pipe passes the signal on to the next piece. Once machine B receives a ping from machine A it knows it is connected.
Store the network and connections in a graph. Each time the graph changes use a graph search method to see if a path exists between the pieces of equipment. Dijkstra may be a good place to start.
The choice of methods is up to you. The first method will be easier to implement, but in most cases will be more expensive in terms of performance. You’ll also need strategies to deal with loops.
So everytime you place a pipe you add it to the corresponding array element. Then you iterate your array by a loop that checks each space with what is next to it, until it either reaches nothing or it reaches another machine.
If the objects are not placed in discrete grid spaces then you could used colliders to tell what objects are touching each other. Or maybe just use colliders anyway? Something like:
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "pipe")
{
// machine is touching this pipe
}
}