How Do I detect this connection?

As you can see from the image above. there are two machines and a pipe connecting them, the pipe is made of individual pieces as they can be placed by the user. I Have a problem where I cannot figure a way to make the two machines know they are connected.

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

bump, I Really need this to work :frowning:

Just a suggestion, but why not try trigger colliders on the ends of the pipes?

And maybe you could then have special triggers that let a pipe know it’s connected to Machine A or B. Such a thing could be done like this: When the player places a pipe, have it parented to a gameobject of which the pipe segments are the children. For each pipe segment, a script on the parent object can then check that all pipes are connected to one of the other pipes. Then, if it also detects that two or more pipes have a machine on one end. (And all the pipes have a connection as well!) then it would register connected.

The only issue is getting two different pipe networks to work, as depending on how this is implemented, it could end up that it’s checking two sets of pipes instead. One way to combat this problem would be to create a new array for each set of pipes. that way, by checking the ends, (With OnTriggerStay, of course) if said array of pipes have all connected ends, (And two or more of the ends are attached to machines) then the machines are said to be connected. when that hapens, just have a boolean in your code to set when this happens. (Or not… :smile:)

EDIT: Also, sorry for late reply, all this typing gets slow sometimes… :smile: (Funny part was, while I was typing, your post appeared and… :p)

Thanks for the reply, im not entierly sure what you mean. But I have managed to get it to work one way, so if I connect asll the pipes together to both machines. it registers and works. but if I remove on of the pipes. i cannot think of a way to update all the other pipes to say its not connected. Thankyou though :slight_smile:

Im sorry to bump this but again I really need this to work

The way to do it:
I did forget one thing, and that is believe it or not, the removal of pipes! :wink:

if you’re removing a pipe, the triggers should have a OnTriggerExit event that checks if the trigger that passed out of the collider (or the trigger itself was moved out) is another pipe, and if so, set the connected variable to false.

Also, using onTriggerEnter to initially activate the variable will make it more stable. :slight_smile:

I also thought of another good way to make things smoother: why not a variable for checking either end, rather than both? :slight_smile:

EDIT: OOPS! Mean’t good! :face_with_spiral_eyes: :smile:

Hmm well I will try and make what you said, I Will post it again soon to show you , and thanks again for the reply!

You’re welcome man! anytime. :slight_smile:

I have to go anyway, so… :smile:

Do you have skype or something so I can talk toi you. I Seriously need help on this

Don’t have skype, no. Sorry! :expressionless:

But if I can think of an alternative (I am not much of a SM junkie, and not allowed to be anyway… :smile:) I will let you know. :slight_smile:

Okay well I will show you the code I have so far. It works one way, so if I link any pipes up and aslong as one is linked to the machine they call register as being connected to the “casher” aka machine. I Will show you the code but like I said it works one way. if i remove one of the pies they still thinkt hey are connected.

#pragma strict
public var isConnectedToCasher : boolean;
function Start () {
}
function Update () {
}
function OnCollisionEnter(collision : Collision){
if(collision.transform.tag==“Pipe”){

if(collision.transform.GetComponent(PipeManager).isConnectedToCasher==true){

isConnectedToCasher=true;

}

}

if(collision.transform.tag==“Cookie Casher”){

isConnectedToCasher=true;

Debug.Log(“Collided”);

}

}
function OnCollisionStay(collision : Collision){
updatePipe(collision);

}
function OnCollisionExit(collision : Collision){
if(collision.transform.tag==“Pipe”){

}
}
//THIS IS TO STOP THE LAG OF GETTING COMPONENT LIKE 20 TIMES A FRAME XD
function updatePipe(collision : Collision){
if(collision.transform.tag==“Cookie Casher”){

isConnectedToCasher=true;

}
if(collision.transform.tag==“Pipe”){

if(collision.transform.gameObject.GetComponent(PipeManager).isConnectedToCasher==true){

isConnectedToCasher=true;

}else{

isConnectedToCasher=false;

}

}

yield WaitForSeconds(1);
}

Ok, that looks complex! What I would have used would be something similar to this:

//this code assumes you use a triggerbox for each end of one pipe segment
function OnTriggerEnter (info : Collider) {
if (info.gameObject.CompareTag("PipeNozzleA")){
connectedA = true;
}
}

For the trigger tags, write A and B, then set them in your code accordingly. Have to go, so will give better explanation later