void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; initialPosSetY = true; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { bones[i].gameObject.SetActive(false); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; } if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = GetJointPosition(manager, userID, (int)KinectInterop.JointType.SpineBase); Vector3 posPointManWorld = new Vector3(posPointMan.x, posPointMan.y, invertedZMovement ? -posPointMan.z : posPointMan.z) + originPosition; Vector3 posPointManHips = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z) + originPosition; // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; initialPosOffset = posPointManWorld; } if (!verticalMovement && !initialPosSetY) { float fFootPosY = 0f; if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.FootLeft)) { fFootPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.FootLeft).y; } else if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.FootRight)) { fFootPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.FootRight).y; } initialPosOffset.y = posPointManWorld.y - (fFootPosY + originPosition.y); initialPosSetY = true; } Vector3 relPosUser = (posPointManWorld - initialPosOffset); //relPosUser.z = invertedZMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); if (manager.IsJointTracked(userID, (int)KinectInterop.JointType.Head)) { // float fHeadPosY = GetJointPosition(manager, userID, (int)KinectInterop.JointType.Head).y + originPosition.y; // float halfHeight = Mathf.Abs(fHeadPosY - posPointManWorld.y); // // CapsuleCollider collider = GetComponent<CapsuleCollider>(); // if(collider != null) // { // collider.height = 2f * halfHeight; // } } // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] == null && bodyJoint != null) { if (!DrawLowerHalf && (i > 11)) { break; } bones[i] = Instantiate(bodyJoint) as GameObject; bones[i].transform.parent = transform; bones[i].name = ((KinectInterop.JointType)i).ToString(); // if(Array.IndexOf(ColliderJoints, i) >= 0) // { // bones[i].GetComponent<SphereCollider>().radius = 1f; // } } if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = GetJointPosition(manager, userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; if (posJoint == Vector3.zero) { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } continue; } posJoint += originPosition; posJoint -= posPointManHips; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && i > 0 && skeletonLine != null) { lines[i] = Instantiate(skeletonLine) as GameObject; lines[i].transform.parent = transform; lines[i].name = ((KinectInterop.JointType)i).ToString() + "_Line"; } if (lines[i] != null && i > 0) { int jParent = (int)manager.GetParentJoint((KinectInterop.JointType)joint); if (manager.IsJointTracked(userID, jParent)) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = GetJointPosition(manager, userID, jParent); posJoint2.z = !mirroredMovement ? -posJoint2.z : posJoint2.z; if (posJoint2 == Vector3.zero) { lines[i].gameObject.SetActive(false); continue; } posJoint2 += originPosition; posJoint2 -= posPointManHips; if (mirroredMovement) { posJoint2.x = -posJoint2.x; posJoint2.z = -posJoint2.z; } Vector3 dirFromParent = posJoint - posJoint2; lines [i].transform.localPosition = posJoint2 + dirFromParent / 2f; lines [i].transform.up = transform.rotation * dirFromParent.normalized; Vector3 lineScale = lines [i].transform.localScale; lines [i].transform.localScale = new Vector3(lineScale.x, dirFromParent.magnitude / 2f, lineScale.z); } else { lines[i].gameObject.SetActive(false); } } } else { if (bones[i] != null) { bones[i].gameObject.SetActive(false); } if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetPrimaryUserID() : 0; if (userID <= 0) { // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (LinePrefab) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); posPointMan.z = !MirroredMovement ? -posPointMan.z : posPointMan.z; // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; initialPosOffset = transform.position - (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z)); } transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z)); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = (int)manager.GetJointAtIndex( !MirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i)); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !MirroredMovement); posJoint -= posPointMan; if (MirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.localRotation = rotJoint; if (LinePrefab) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !MirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } // KinectInterop.BodyData bodyData = manager.GetUserBodyData(userID); // if(lineTLeft != null && bodyData.liTrackingID != 0 && joint == (int)JointType.HandLeft) // { // Vector3 leftTDir = bodyData.leftThumbDirection.normalized; // leftTDir.z = !MirroredMovement ? -leftTDir.z : leftTDir.z; // // Vector3 posTStart = bones[i].transform.position; // Vector3 posTEnd = posTStart + leftTDir; // // lineTLeft.SetPosition(0, posTStart); // lineTLeft.SetPosition(1, posTEnd); // // if(lineFLeft != null) // { // Vector3 leftFDir = bodyData.leftThumbForward.normalized; // leftFDir.z = !MirroredMovement ? -leftFDir.z : leftFDir.z; // // Vector3 posFStart = bones[i].transform.position; // Vector3 posFEnd = posTStart + leftFDir; // // lineFLeft.SetPosition(0, posFStart); // lineFLeft.SetPosition(1, posFEnd); // } // } // // if(lineTRight != null && bodyData.liTrackingID != 0 && joint == (int)JointType.HandRight) // { // Vector3 rightTDir = bodyData.rightThumbDirection.normalized; // rightTDir.z = !MirroredMovement ? -rightTDir.z : rightTDir.z; // // Vector3 posTStart = bones[i].transform.position; // Vector3 posTEnd = posTStart + rightTDir; // // lineTRight.SetPosition(0, posTStart); // lineTRight.SetPosition(1, posTEnd); // // if(lineFRight != null) // { // Vector3 rightFDir = bodyData.rightThumbForward.normalized; // rightFDir.z = !MirroredMovement ? -rightFDir.z : rightFDir.z; // // Vector3 posFStart = bones[i].transform.position; // Vector3 posFEnd = posTStart + rightFDir; // // lineFRight.SetPosition(0, posFStart); // lineFRight.SetPosition(1, posFEnd); // } // } } else { bones[i].gameObject.SetActive(false); if (LinePrefab) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetPrimaryUserID() : 0; /* * if(userID <= 0) * { * // reset the pointman position and rotation * if(transform.position != initialPosition) * transform.position = initialPosition; * * if(transform.rotation != initialRotation) * transform.rotation = initialRotation; * * for(int i = 0; i < bones.Length; i++) * { * bones[i].gameObject.SetActive(true); * * bones[i].transform.localPosition = Vector3.zero; * bones[i].transform.localRotation = Quaternion.identity; * * if(LinePrefab) * { * lines[i].gameObject.SetActive(false); * } * } * * return; * } * * // set the position in space * Vector3 posPointMan = manager.GetUserPosition(userID); * posPointMan.z = !MirroredMovement ? -posPointMan.z : posPointMan.z; * * // store the initial position * if(initialPosUserID != userID) * { * initialPosUserID = userID; * initialPosOffset = transform.position - (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z)); * } * * transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z)); */ // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !MirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); //int joint = (int)manager.GetJointAtIndex( // !MirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i)); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { if (joint == 0) { if (torsoOn) { bones[i].gameObject.SetActive(true); } } else { } } else if (joint == 4) { if (leftArmOn) { bones[i].gameObject.SetActive(true); } else { } } else if (joint == 8) { if (rightArmOn) { bones[i].gameObject.SetActive(true); } else { } } else { bones[i].gameObject.SetActive(true); } Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !MirroredMovement); if (i == 0) { hipRotation = rotJoint.eulerAngles; } //bones[i].transform.localPosition = posJoint; bones[i].transform.localRotation = rotJoint; } else { //bones[i].gameObject.SetActive(false); } } Vector3 leftTip = manager.GetJointPosition(userID, 21); Vector3 leftThumb = manager.GetJointPosition(userID, 22); Vector3 rightTip = manager.GetJointPosition(userID, 23); Vector3 rightThumb = manager.GetJointPosition(userID, 24); leftHandDist = Vector3.Distance(leftTip, leftThumb); rightHandDist = Vector3.Distance(rightTip, rightThumb); }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (skeletonLine) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (skeletonLine) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } } else { bones[i].gameObject.SetActive(false); if (skeletonLine) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; Int64 userID = 0; if (AvatarRecorded) { userID = manager.GetUserIdRecorded(); } else { // get 1st player //userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; userID = manager ? manager.GetUserNormalId() : 0; //if (manager.IsRecordedUser(userID)) // userID = 0; } if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosition + initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); bones[i].gameObject.GetComponent <Renderer>().enabled = mostrar; Vector3 posJoint = manager.GetJointPosition(userID, joint); //if (joint == 7 || joint == 11) // Debug.Log("Player : "+ playerIndex + " Joint " + joint + " pos: " + posJoint); //Debug.Log("Avatar " +i + " " +posJoint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate((i == 22 || i == 24) && debugLine ? debugLine : skeletonLine) as LineRenderer; lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(mostrar); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
// reads a line from the file private bool ReadFile(string file) { if (file == null) { return(false); } // stop playing if there is no file name specified //if (file.Length == 0 || !File.Exists(file)) //{ // Debug.LogError("No file to play."); // /* if (infoText != null) // { // infoText.text = "No file to play."; // } // */ //} // open the file and read a line #if !UNITY_WSA TextAsset asset = Resources.Load("movimientos/" + file) as TextAsset; // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(asset.text); //byte[] byteArray = Encoding.ASCII.GetBytes(contents); MemoryStream stream = new MemoryStream(byteArray); StreamReader fileReader = new StreamReader(stream); #endif sPlayLine = fileReader.ReadLine(); while (sPlayLine != null) { // extract the unity time and the body frame char[] delimiters = { '|' }; string[] sLineParts = sPlayLine.Split(delimiters); float.TryParse(sLineParts[0], out this.Gest_Time); if (sLineParts.Length >= 2) { // float.TryParse(sLineParts[0], out fPlayTime); sPlayLine = sLineParts[1]; // fCurrentFrame++; } //para cada joint char[] delimiter = { ',' }; string[] alCsvParts = sPlayLine.Split(delimiter); // check the id, body count & joint count int jointCount = 0; int.TryParse(alCsvParts[3], out jointCount); Vector3[] movimiento = new Vector3[jointCount]; int iIndex = 4; while (alCsvParts[iIndex] == "0") { iIndex++; } iIndex = iIndex + 3; // update joints' data for (int j = 0; j < jointCount; j++) { if (alCsvParts.Length >= (iIndex + 1)) { float x = 0f, y = 0f, z = 0f; float.TryParse(alCsvParts[iIndex], out x); float.TryParse(alCsvParts[iIndex + 1], out y); float.TryParse(alCsvParts[iIndex + 2], out z); iIndex += 4; //por el movimiento de espejo int joint = (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)j); Vector3 current_joint = new Vector3(x, y, z); current_joint.x = -current_joint.x; current_joint.z = -current_joint.z; KinectManager manager = KinectManager.Instance; current_joint = manager.GetKinectToWorldMatrix().MultiplyPoint3x4(current_joint); movimiento[joint] = current_joint; if (j > 0) { movimiento[joint] = movimiento[joint] - movimiento[0]; } //if (joint == 4) // Debug.Log("Tranformado : "+ movimiento[joint]); } } movimientos.Add(movimiento); // read a line sPlayLine = fileReader.ReadLine(); } // close the file and disable the play mode fileReader.Dispose(); fileReader = null; return(true); }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player //if (Input.GetKeyDown (KeyCode.Alpha1)) { //userID = manager.GetPrimaryUserID (); userID = manager.alUserIds[PLAYERNUM - 1]; //Debug.Log("1pressed "+userID); // } /* * if(userID <= 0) * { * // reset the pointman position and rotation * if(transform.position != initialPosition) * transform.position = initialPosition; * * if(transform.rotation != initialRotation) * transform.rotation = initialRotation; * * for(int i = 0; i < bones.Length; i++) * { * bones[i].gameObject.SetActive(true); * * bones[i].transform.localPosition = Vector3.zero; * bones[i].transform.localRotation = Quaternion.identity; * } * * return; * } */ // transform.position = initialPosOffset + (MoveVertically ? posPointMan : new Vector3(posPointMan.x, 0, posPointMan.z)); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = (int)manager.GetJointAtIndex( !MirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i)); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !MirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !MirroredMovement); //bones[i].transform.localPosition = posJoint; bones[i].transform.localRotation = rotJoint; } else { //bones[i].gameObject.SetActive(false); } } } Vector3 leftTemp = manager.GetJointPosition(userID, 14); Vector3 rightTemp = manager.GetJointPosition(userID, 18); if (checkKicks == true) { if (Mathf.Abs(leftTemp.z - leftAnklePos.z) >= stepSensitivity) { stepAnim.SetBool("stepLeft", true); } if (Mathf.Abs(rightTemp.z - rightAnklePos.z) >= stepSensitivity) { stepAnim.SetBool("stepRight", true); } } leftAnklePos = leftTemp; rightAnklePos = rightTemp; checkKicks = true; }
void Update() { KinectManager kinectManager = KinectManager.Instance; // get 1st player ulong userID = kinectManager ? kinectManager.GetUserIdByIndex(playerIndex) : 0; if (userID == 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; initialPosUser = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = !sensorTransform?kinectManager.GetUserPosition(userID) : kinectManager.GetUserKinectPosition(userID, true); if (sensorTransform) { posPointMan = sensorTransform.TransformPoint(posPointMan); } Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; initialPosUser = initialPosition; if (verticalMovement) { initialPosUser.y = 0f; // posPointManMP.y provides the vertical position in this case } } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = verticalMovement ? initialPosUser + posPointManMP * moveRate : initialPosUser + new Vector3(posPointManMP.x, 0, posPointManMP.z) * moveRate; //Debug.Log (userID + ", pos: " + posPointMan + ", ipos: " + initialPosUser + ", rpos: " + posPointManMP + ", tpos: " + transform.position); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (kinectManager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = !sensorTransform?kinectManager.GetJointPosition(userID, joint) : kinectManager.GetJointKinectPosition(userID, joint, true); if (sensorTransform) { posJoint = sensorTransform.TransformPoint(posJoint); } posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = kinectManager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate(skeletonLine) as LineRenderer; lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = kinectManager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate((i == 22 || i == 24) && debugLine ? debugLine : skeletonLine) as LineRenderer; lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } ///MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /// <summary> /// Version: Controlling PITCH with velocity of left hand joint /// </summary> if (i == 6) //left hand on cube man. remember he is mirrored (your right hand) { float velocity = Vector3.Distance(lastPos, posJoint) / Time.deltaTime; print("current: " + posJoint.magnitude + " last: " + lastPos.magnitude); //print("Distance to other: " + vectorDist + " pos: " + posJoint.x + " , " + posJoint.y + " , " + posJoint.z); lastPos = posJoint; velSum += velocity; FilterCounter++; if (FilterCounter % 3 == 0) { if (velSum > 0.3f) //move, and pitch increases { if (pitch < 1.5f) { pitch += 0.001f * velSum; theMixer.SetFloat("1_PitchShift", pitch); } } else if (pitch > 0.4f) //if you dont move, pitch decreases { pitch -= 0.03f; theMixer.SetFloat("1_PitchShift", pitch); } FilterCounter = 0; velSum = 0; } } //MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // OLD Testing Version: Controls PITCH relative to the distance of hip center and both hands // REMEMBER to outcomment the other version if you use this /* * if (i == 6) * { * Vector3 leftHandPos = bones[7].transform.localPosition; * Vector3 RightHandPos = bones[11].transform.localPosition; * Vector3 HipCenterPos = bones[0].transform.localPosition; * * float dist = Vector3.Distance(leftHandPos, HipCenterPos) + Vector3.Distance(RightHandPos, HipCenterPos); * * float RangeConvertedPitchValue = (((dist - oldMin) * newRange) / oldRange) + newMin; * //print("dist: " + RangeConvertedPitchValue); * * theMixer.SetFloat("1_PitchShift", RangeConvertedPitchValue); * } */ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void FixedUpdate() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate((i == 22 || i == 24) && debugLine ? debugLine : skeletonLine) as LineRenderer; lines[i].gameObject.name = "Line" + i; //lines[1].SetColors(Color.red, Color.red); lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } ///MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (i == bones.Length - 1) { hipCenRot = bones[0].transform.rotation; hipCenVec = bones[0].transform.position; hipLeftPos = bones[12].transform.position; hipRightPos = bones[16].transform.position; neckVec = bones[2].transform.position; shoulderCenVec = bones[1].transform.position; wristLeftPos = bones[6].transform.position; wristRightPos = bones[10].transform.position; elbowLeftPos = bones[5].transform.position; elbowRightPos = bones[9].transform.position; if (!hasValues) { hasValues = true; } } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate((i == 22 || i == 24) && debugLine ? debugLine : skeletonLine) as LineRenderer; lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } ///MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (i == 6) { Vector3 HipCenterPos = bones[0].transform.localPosition; Vector3 shoulderCenterPos = bones[1].transform.localPosition; dist = CalXZdist(HipCenterPos, shoulderCenterPos); if (dist > maxDist) { dist = maxDist; } highPassFilterVal = minFreq * Math.Pow((Math.Pow((maxFreq / minFreq), (1 / interval))), (maxDist - dist)); theMixer.SetFloat("Torso_CutOffFreqHP", (float)highPassFilterVal); //Debug.Log("dist: " + dist + " highPassFilterVal: " + highPassFilterVal); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { //MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (!isAttenReset) { theMixer.SetFloat("Torso_Attenuation", -50); isAttenReset = true; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ KinectManager manager = KinectManager.Instance; // get 1st player Int64 userID = manager ? manager.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { initialPosUserID = 0; initialPosOffset = Vector3.zero; // reset the pointman position and rotation if (transform.position != initialPosition) { transform.position = initialPosition; } if (transform.rotation != initialRotation) { transform.rotation = initialRotation; } for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } return; } // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); Vector3 posPointManMP = new Vector3(posPointMan.x, posPointMan.y, !mirroredMovement ? -posPointMan.z : posPointMan.z); // store the initial position if (initialPosUserID != userID) { initialPosUserID = userID; //initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); initialPosOffset = posPointMan; } Vector3 relPosUser = (posPointMan - initialPosOffset); relPosUser.z = !mirroredMovement ? -relPosUser.z : relPosUser.z; transform.position = initialPosOffset + (verticalMovement ? relPosUser * moveRate : new Vector3(relPosUser.x, 0, relPosUser.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = initialRotation * rotJoint; posJoint -= posPointManMP; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (lines[i] == null && skeletonLine != null) { lines[i] = Instantiate((i == 22 || i == 24) && debugLine ? debugLine : skeletonLine) as LineRenderer; lines[i].transform.parent = transform; } if (lines[i] != null) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } ///MED7 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (i == 6) { Vector3 posHipCenter = bones[0].transform.localPosition; Vector3 posShoulderCenter = bones[1].transform.localPosition; Vector3 posNeck = bones[2].transform.localPosition; distHipShoulder = CalXZdist(posShoulderCenter, posHipCenter); distShoulderNeck = CalXZdist(posShoulderCenter, posNeck); totalDist = distHipShoulder + distShoulderNeck; totalAttenuation = ScalingBetween(totalDist, minAtten, maxAtten, minDist, maxDist); //testing this... float linear = totalAttenuation; double hepson = (70 * Math.Log10(((double)totalAttenuation / 2) + 42)) - 80; totalAttenuation = (float)hepson + 20; Debug.Log("OFF linear: " + linear + " ON log: " + hepson); if (totalAttenuation > maxAtten) { totalAttenuation = maxAtten; } else if (totalAttenuation < minAtten) { totalAttenuation = minAtten; } theMixer.SetFloat("Torso_Attenuation", totalAttenuation); //Debug.Log("totalDist: " + totalDist + " totalAttenuation: " + totalAttenuation); //--------------------------------------------------------------------------- //current problem: only 2 points... float AxisZ = posHipCenter.z - posShoulderCenter.z; float AxisX = posHipCenter.x - posShoulderCenter.x; if (AxisZ < 0) { NegaScaledAxisZ = ScalingBetween(-AxisZ, 0.3f, 1f, minAxis, maxAxis); theMixer.SetFloat("Torso_EqFreqGain_00", NegaScaledAxisZ); } else if (AxisZ >= 0) { PosiScaledAxisZ = ScalingBetween(AxisZ, 0.3f, 1f, minAxis, maxAxis); theMixer.SetFloat("Torso_EqFreqGain_01", PosiScaledAxisZ); } if (AxisX < 0) { NegaScaledAxisX = ScalingBetween(-AxisX, 0.3f, 1f, minAxis, maxAxis); theMixer.SetFloat("Torso_EqFreqGain_02", NegaScaledAxisX); } else if (AxisX >= 0) { PosiScaledAxisX = ScalingBetween(AxisX, 0.3f, 1f, minAxis, maxAxis); theMixer.SetFloat("Torso_EqFreqGain_03", PosiScaledAxisX); } //Debug.Log("negZ: " + NegaScaledAxisZ + " posZ: " + PosiScaledAxisZ + " negX: " + NegaScaledAxisX + " posX: " + PosiScaledAxisX); //------------------------------------------------------------------------------- //Score score = 100 - ScalingBetween(totalDist, 0, 100, minDist, maxDist); if (score < 0) { score = 0; } else if (score > 100) { score = 100; } //Debug.Log("score: " + score); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } else { bones[i].gameObject.SetActive(false); if (lines[i] != null) { lines[i].gameObject.SetActive(false); } } } } }
void Update() { KinectManager manager = KinectManager.Instance; // if(manager.GetUserIdByIndex(playerIndex) != userID || manager.GetUserIdByIndex(playerIndex) == -1) // { // Destroy(gameObject); // CharacterManager.Instance.numCharacters --; // } userID = KinectManager.Instance ? KinectManager.Instance.GetUserIdByIndex(playerIndex) : 0; if (userID <= 0) { for (int i = 0; i < bones.Length; i++) { bones[i].gameObject.SetActive(true); bones[i].transform.localPosition = Vector3.zero; bones[i].transform.localRotation = Quaternion.identity; if (skeletonLine) { lines[i].gameObject.SetActive(false); } } return; } //TODO: verify two dancer interaction // set the position in space Vector3 posPointMan = manager.GetUserPosition(userID); posPointMan.z = !mirroredMovement ? -posPointMan.z : posPointMan.z; // store the initial position // if(initialPosUserID != userID) // { // initialPosUserID = userID; // initialPosOffset = transform.position - (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); // } transform.position = (verticalMovement ? posPointMan * moveRate : new Vector3(posPointMan.x, 0, posPointMan.z) * moveRate); // update the local positions of the bones for (int i = 0; i < bones.Length; i++) { if (bones[i] != null) { int joint = (int)manager.GetJointAtIndex( !mirroredMovement ? i : (int)KinectInterop.GetMirrorJoint((KinectInterop.JointType)i)); if (joint < 0) { continue; } if (manager.IsJointTracked(userID, joint)) { bones[i].gameObject.SetActive(true); Vector3 posJoint = manager.GetJointPosition(userID, joint); posJoint.z = !mirroredMovement ? -posJoint.z : posJoint.z; Quaternion rotJoint = manager.GetJointOrientation(userID, joint, !mirroredMovement); rotJoint = rotJoint; posJoint -= posPointMan; if (mirroredMovement) { posJoint.x = -posJoint.x; posJoint.z = -posJoint.z; } bones[i].transform.localPosition = posJoint; bones[i].transform.rotation = rotJoint; if (skeletonLine) { lines[i].gameObject.SetActive(true); Vector3 posJoint2 = bones[i].transform.position; Vector3 dirFromParent = manager.GetJointDirection(userID, joint, false, false); dirFromParent.z = !mirroredMovement ? -dirFromParent.z : dirFromParent.z; Vector3 posParent = posJoint2 - dirFromParent; //lines[i].SetVertexCount(2); lines[i].SetPosition(0, posParent); lines[i].SetPosition(1, posJoint2); } } else { bones[i].gameObject.SetActive(false); if (skeletonLine) { lines[i].gameObject.SetActive(false); } } } } }