GameObject CreateConnection(Transform kid, Transform dad, GameObject grandDadBone, bool first) { Vector3 dir = kid.position - dad.position; Vector3 fPos = dad.position; //fPos = new Vector3( 0,0,0); GameObject connection = Instantiate(connectionPrefab, fPos, dad.rotation); ConnectionLinker dadCL = grandDadBone.GetComponent <ConnectionLinker>(); connection.GetComponent <ConfigurableJoint>().connectedBody = grandDadBone.GetComponent <Rigidbody>(); //print( dadCL.Length ); if (first == true) { connection.GetComponent <ConfigurableJoint>().connectedAnchor = new Vector3(0, 0, 0); connection.GetComponent <Rigidbody>().isKinematic = true; } else { connection.GetComponent <ConfigurableJoint>().connectedAnchor = new Vector3(0, 2, 0); } connection.GetComponent <ConfigurableJoint>().anchor = new Vector3(0, 0, 0); // print( "MAg"); // print( dir.magnitude ); //print( "connected"); //print( dadCL.Length ); connection.transform.localScale = new Vector3(dir.magnitude * .5f, dir.magnitude * .5f, dir.magnitude * .5f); connection.GetComponent <ConnectionLinker>().Length = dir.magnitude; dad.gameObject.GetComponent <BoneLinker>().DadConnection = grandDadBone; dad.gameObject.GetComponent <BoneLinker>().Connection = connection; // print( grandDadBone ); //connection.transform.parent = dad; //connection.transform.rotation = dad.rotation;//Quaternion.LookRotation(dir); return(connection); }
GameObject CreateConnection(Transform kid, Transform dad, GameObject dadConnection) { Vector3 dir = kid.position - dad.position; Vector3 fPos = kid.position + dir * .5f; GameObject connection = Instantiate(connectionPrefab, fPos, Quaternion.identity); ConnectionLinker dadCL = dadConnection.GetComponent <ConnectionLinker>(); BoneLinker dadBL = dad.GetComponent <BoneLinker>(); connection.GetComponent <SpringJoint>().connectedBody = dadConnection.GetComponent <Rigidbody>(); connection.GetComponent <SpringJoint>().connectedAnchor = new Vector3(0, dadCL.Length * .5f, 0); connection.GetComponent <SpringJoint>().anchor = new Vector3(0, dir.magnitude * -.5f, 0); connection.transform.localScale = new Vector3(dadBL.BoneWidth, dir.magnitude * .5f, dadBL.BoneWidth); connection.GetComponent <ConnectionLinker>().Length = dir.magnitude; return(connection); }