public static SimplePart WhoControlsJoint(SimplePart sp1, SimplePart sp2) { if (sp1 is Membrane m1 && sp2 is Membrane m2) { // sp1 is the default controller if niether has an actual joint if (GetJoint(sp2, sp1) == null) { return(sp1); } else { return(sp2); } } if (sp1.JointDesire(sp2) > sp2.JointDesire(sp1)) { return(sp1); } else if (sp1.JointDesire(sp2) == sp2.JointDesire(sp1)) { // If same desire, choose arbitrariliy but consistently. return(sp1.GetInstanceID() < sp2.GetInstanceID() ? sp1 : sp2); } else { return(sp2); } }