public float GetHeight() { if (Time.time - lastUpdate < UPDATE_RATE) { return(height); } if (isNotInit) { Init(); } height = 0; Vector3 postition1 = player.GetBonePosition(HumanBodyBones.Head); Vector3 postition2 = player.GetBonePosition(HumanBodyBones.Neck); height += Vector3.Distance(postition1, postition2); postition1 = player.GetBonePosition(HumanBodyBones.Hips); height += Vector3.Distance(postition1, postition2); postition2 = player.GetBonePosition(HumanBodyBones.RightLowerLeg); height += Vector3.Distance(postition1, postition2); postition1 = player.GetBonePosition(HumanBodyBones.RightFoot); height += Vector3.Distance(postition1, postition2); height *= 1.15f; // Adjusting for head if (height == 0) { height = 1; //For non humanoids } lastUpdate = Time.time; return(height); }
private void SetToMostPreciseFingerPosition(Transform target, VRCPlayerApi.TrackingDataType trackingDataType, HumanBodyBones bone1, HumanBodyBones bone2, HumanBodyBones bone3) { Vector3 positionHead = _player.GetBonePosition(bone3); Vector3 positionTail = _player.GetBonePosition(bone2); if (positionHead != Vector3.zero) { target.position = positionHead; target.rotation = Quaternion.LookRotation(positionHead - positionTail); return; } positionHead = positionTail; positionTail = _player.GetBonePosition(bone1); if (positionHead != Vector3.zero) { target.position = positionHead; target.rotation = Quaternion.LookRotation(positionHead - positionTail); return; } VRCPlayerApi.TrackingData trackingData = _player.GetTrackingData(trackingDataType); positionHead = positionTail; positionTail = trackingData.position; if (positionHead != Vector3.zero) { target.position = positionHead; target.rotation = Quaternion.LookRotation(positionHead - positionTail); return; } target.position = trackingData.position; target.rotation = trackingData.rotation; }
private void Update() { if (!isRecording) { return; } if (time - beforetime > SecondsPerRecord) { if (recordAllPlayers) { VRCPlayerApi.GetPlayers(players); } for (int i = 0; i < players.Length; i++) { if (players[i] == null) { continue; } player = players[i]; string strOutputLog = "HUMR:"; strOutputLog += player.displayName; strOutputLog += time.ToString(); strOutputLog += ","; //hipbone = root strOutputLog += player.GetBonePosition(HumanBodyBones.Hips).x.ToString("F7"); strOutputLog += ","; strOutputLog += player.GetBonePosition(HumanBodyBones.Hips).y.ToString("F7"); strOutputLog += ","; strOutputLog += player.GetBonePosition(HumanBodyBones.Hips).z.ToString("F7"); for (int j = 0; j < bonerotation.Length; j++) { bonerotation[j] = player.GetBoneRotation((HumanBodyBones)j); strOutputLog += ","; strOutputLog += bonerotation[j].x.ToString("F7"); strOutputLog += ","; strOutputLog += bonerotation[j].y.ToString("F7"); strOutputLog += ","; strOutputLog += bonerotation[j].z.ToString("F7"); strOutputLog += ","; strOutputLog += bonerotation[j].w.ToString("F7"); } Debug.Log(strOutputLog); beforetime = time; } } time += Time.deltaTime; }
private void Update() { if (isEditor || !trackBone) { return; } Vector3 targetPos; Quaternion targetRot; targetPos = player.GetBonePosition(bone); targetRot = player.GetBoneRotation(bone); if (trackPosition && trackRotation) { targetTransform.SetPositionAndRotation(targetPos, targetRot); } else if (trackPosition) { targetTransform.position = targetPos; } else { targetTransform.rotation = targetRot; } if (rotateBy.magnitude > 0) { targetTransform.Rotate(rotateBy); } }
void LateUpdate() { if (isInEditor) { return; } transform.SetPositionAndRotation(playerApi.GetBonePosition(trackedBone), playerApi.GetBoneRotation(trackedBone)); }
//--------------PLAYER HEIGHT---------------- public float GetAvatarHeight(VRCPlayerApi player) { float height = 0; Vector3 postition1 = player.GetBonePosition(HumanBodyBones.Head); Vector3 postition2 = player.GetBonePosition(HumanBodyBones.Neck); height += (postition1 - postition2).magnitude; postition1 = postition2; postition2 = player.GetBonePosition(HumanBodyBones.Hips); height += (postition1 - postition2).magnitude; postition1 = postition2; postition2 = player.GetBonePosition(HumanBodyBones.RightLowerLeg); height += (postition1 - postition2).magnitude; postition1 = postition2; postition2 = player.GetBonePosition(HumanBodyBones.RightFoot); height += (postition1 - postition2).magnitude; return(height > 0 ? height : 1); }
public float GetAvatarHeight(VRCPlayerApi player) { float height = 0; Vector3 postition1 = player.GetBonePosition(HumanBodyBones.Head); Vector3 postition2 = player.GetBonePosition(HumanBodyBones.Neck); height += Vector3.Distance(postition1, postition2); postition1 = player.GetBonePosition(HumanBodyBones.Hips); height += Vector3.Distance(postition1, postition2); isHumanoid = height > 0; if (!isHumanoid) { return(Vector3.Distance(player.GetPosition(), player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).position) * 1.15f); //For non humanoids } postition2 = player.GetBonePosition(HumanBodyBones.RightLowerLeg); height += Vector3.Distance(postition1, postition2); postition1 = player.GetBonePosition(HumanBodyBones.RightFoot); height += Vector3.Distance(postition1, postition2); height *= 1.15f; // Adjusting for head return(height); }
public override void PostLateUpdate() { //Roation transform.rotation = player.GetTrackingData(trackingDataType).rotation; transform.Rotate(0, 55, 0); //Position Vector3 handPosition = player.GetBonePosition(finger); if (handPosition == Vector3.zero) { handPosition = player.GetBonePosition(hand); } if (handPosition == Vector3.zero) { handPosition = player.GetTrackingData(trackingDataType).position; } //Velcoity _velocity = (transform.position - handPosition) / Time.deltaTime; //Set position transform.position = handPosition; }
private void LateUpdate() { // 追従するプレイヤーのLocalで処理をする if (isTracking) { // 追従オブジェクトと追従するプレイヤーとの場所の差分 var distance = characterRoot.position - player.GetPosition(); // ボーンの位置を反映させる headPoint.position = player.GetBonePosition(HumanBodyBones.Head) + distance; headPoint.rotation = player.GetBoneRotation(HumanBodyBones.Head); hipPoint.position = player.GetBonePosition(HumanBodyBones.Hips) + distance; hipPoint.rotation = player.GetBoneRotation(HumanBodyBones.Hips); lhandPoint.position = player.GetBonePosition(HumanBodyBones.LeftHand) + distance; lhandPoint.rotation = player.GetBoneRotation(HumanBodyBones.LeftHand); rhandPoint.position = player.GetBonePosition(HumanBodyBones.RightHand) + distance; rhandPoint.rotation = player.GetBoneRotation(HumanBodyBones.RightHand); lfootPoint.position = player.GetBonePosition(HumanBodyBones.LeftFoot) + distance; lfootPoint.rotation = player.GetBoneRotation(HumanBodyBones.LeftFoot); rfootPoint.position = player.GetBonePosition(HumanBodyBones.RightFoot) + distance; rfootPoint.rotation = player.GetBoneRotation(HumanBodyBones.RightFoot); } }
// なでなでされているかチェック private bool CheckNadenade() { float distance_r; float distance_l; // ラスクちゃんのなでなでポイント(頭)とプレイヤーの手の距離を計算する if (selected > 0) // ボールを投げた後は投げた人をチェックする { GameObject ball = _tgroot.transform.GetChild(selected - 1).gameObject; VRCPlayerApi owner = Networking.GetOwner(ball); if (owner != null) { distance_r = Vector3.Distance(owner.GetBonePosition(HumanBodyBones.RightHand), _nadePosition.position); distance_l = Vector3.Distance(owner.GetBonePosition(HumanBodyBones.LeftHand), _nadePosition.position); if (Mathf.Min(distance_r, distance_l) < nadenade_distance) { naderemain = nadenade_time; } } } else // それ以外はローカルユーザーを見る { distance_r = Vector3.Distance(Networking.LocalPlayer.GetBonePosition(HumanBodyBones.RightHand), _nadePosition.position); distance_l = Vector3.Distance(Networking.LocalPlayer.GetBonePosition(HumanBodyBones.LeftHand), _nadePosition.position); if (Mathf.Min(distance_r, distance_l) < nadenade_distance) { naderemain = nadenade_time; } } // なでなでされたら一定時間有効にする if (naderemain > 0f) { naderemain -= Time.deltaTime; nadenaded = (naderemain > 0f); } return(nadenaded); // 同期変数 }
// 毎フレーム実行される void Update() { if (gamestate == 0) //待機画面 { totalTime += Time.deltaTime; } else if (gamestate == 1) //開始前のカウントダウン { totalTime += Time.deltaTime; if (totalTime >= 2.998f) { SetNextState(); ResetAllTime(); } } else if (gamestate == 2) //ゲーム中 { totalTime += Time.deltaTime; var cubepos = localplayer.GetBonePosition(HumanBodyBones.RightIndexDistal); collidercube.transform.position = cubepos; if (isJamp) { time += Time.deltaTime; height = Mathf.Sin(mypow(PI * time, 0.8f)); height = mypow(height, 1.0f) * 0.5f; campos.y = y + height * 0.3f; judgecam.transform.position = campos; if (height < 0.0) { JumpStateFalse(); } } matdisplay.SetFloat("_Jump", height); } else if (gamestate == 3) //ゲームオーバー { if (isSetRanking == false) { SortRanking(); SetRanking(); isSetRanking = true; totalTime = nowTime; } } matdisplay.SetFloat("_TotalTime", totalTime); }
public void Play() { if (isNotInit) { return; } VRCPlayerApi player = Networking.GetOwner(gameObject); //Update avatar height if (Time.time - lastAvatarHeightUpdate > 10) { avatarHeight = GetAvatarHeight(player); lastAvatarHeightUpdate = Time.time; transform.localScale = Vector3.one * avatarHeight; float pitch = -Mathf.Log(avatarHeight * 0.1f) * 0.4f + 0.2f; pitch = Mathf.Clamp(pitch, 0.2f, 3f); float volume = avatarHeight * 0.3f + 0.5f; volume = Mathf.Clamp(volume, 0.5f, 1f); float distance = avatarHeight * 2; distance = Mathf.Clamp(distance, 1, 10); _audioSource.pitch = pitch; _audioSource.maxDistance = distance; _audioSource.volume = volume; Debug.Log($"[Clapper] Height: {avatarHeight} => pitch: {pitch} => volume: {volume} => distance: {distance}"); } //Set position if (player.IsUserInVR()) { transform.position = Vector3.Lerp(player.GetTrackingData(VRCPlayerApi.TrackingDataType.LeftHand).position, player.GetTrackingData(VRCPlayerApi.TrackingDataType.RightHand).position, 0.5f); } else { transform.position = isHumanoid ? player.GetBonePosition(HumanBodyBones.Chest) : Vector3.Lerp(player.GetPosition(), player.GetTrackingData(VRCPlayerApi.TrackingDataType.Head).position, 0.7f); } transform.rotation = player.GetRotation(); //Play particle and audio source _particleSystem.Emit(1); _audioSource.Play(); }
private void Update() { timeSinceLastBlink += Time.deltaTime; timeSinceLastRecharge += Time.deltaTime; if (timeSinceLastRecharge > cooldownRecharge) { charges += refillAmount; if (charges > maxCharges) { charges = maxCharges; } timeSinceLastRecharge = 0; } // TODO: Some other button might be better for this but idk which one yet. // If jump button is pressed. if ((Input.GetButtonDown("Oculus_CrossPlatform_SecondaryThumbstick") || Input.GetButtonDown("Jump")) && timeSinceLastBlink > cooldownBlink && charges > 0) { blinkDist = maxBlinkDistance; // TODO: This may need to be changed to avatar origin position to prevent clipping into ground with tall avatars. headPos = playerLocal.GetBonePosition(HumanBodyBones.Head); headRot = playerLocal.GetBoneRotation(HumanBodyBones.Head); if (Physics.Raycast(headPos, headRot * Vector3.forward, out rayHit)) { if (rayHit.distance <= maxBlinkDistance) { blinkDist = rayHit.distance; } } playerLocal.TeleportTo(playerLocal.GetPosition() + (headRot * Vector3.forward) * (blinkDist - destinationDistFromCollider), playerLocal.GetRotation()); timeSinceLastBlink = 0; charges--; } }
/// <summary> /// Reads bone positions of all hand bones /// </summary> void ReadBonePositions() { _indexBoneL = _localPlayer.GetBonePosition(_leftIndexBone); _indexBoneR = _localPlayer.GetBonePosition(_rightIndexBone); }
public float getAvatarHeight(VRCPlayerApi player) { /* * // Array no work :< * * Vector3[] bones = { * player.GetBonePosition(HumanBodyBones.Head), * player.GetBonePosition(HumanBodyBones.Neck), * player.GetBonePosition(HumanBodyBones.Chest), * player.GetBonePosition(HumanBodyBones.Spine), * player.GetBonePosition(HumanBodyBones.Hips), * player.GetBonePosition(HumanBodyBones.LeftUpperLeg), * player.GetBonePosition(HumanBodyBones.LeftLowerLeg), * player.GetBonePosition(HumanBodyBones.LeftFoot) * }; */ float height = 0; height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.Head), player.GetBonePosition(HumanBodyBones.Neck) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.Neck), player.GetBonePosition(HumanBodyBones.Chest) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.Chest), player.GetBonePosition(HumanBodyBones.Spine) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.Spine), player.GetBonePosition(HumanBodyBones.Hips) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.Hips), player.GetBonePosition(HumanBodyBones.LeftUpperLeg) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.LeftUpperLeg), player.GetBonePosition(HumanBodyBones.LeftLowerLeg) ); height += Vector3.Distance( player.GetBonePosition(HumanBodyBones.LeftLowerLeg), player.GetBonePosition(HumanBodyBones.LeftFoot) ); return(height); }
private void Update() { VRCPlayerApi player = Networking.LocalPlayer; transform.SetPositionAndRotation(player.GetBonePosition(Bone), player.GetBoneRotation(Bone)); }
void UpdateParticlesPosition(Transform trans, HumanBodyBones referenceBonePosition) { trans.position = player.GetBonePosition(referenceBonePosition); }
void bonesset(HumanBodyBones bone, int index, VRCPlayerApi PlayerApiref) { bonevisuals[index].position = PlayerApiref.GetBonePosition(bone); bonevisuals[index].rotation = PlayerApiref.GetBoneRotation(bone); }
// 毎フレーム実行される void Update() { SetDebugView(); if (isLateJoiner) { time += Time.deltaTime; if (time >= 10.0f) { ResetAllTime(); SetRankingforLateJoiner(); isLateJoiner = false; matdisplay.SetInt("_GameState", 0); } return; } if (isForceSync) { totalTime += Time.deltaTime; if (totalTime > 5.0f) { totalTime = 0.0f; players = VRCPlayerApi.GetPlayers(players); SetRankingforLateJoiner(); isForceSync = false; ResetGameState(); } matdisplay.SetFloat("_TotalTime", totalTime); return; } if (gamestate == 0) //待機画面 { totalTime += Time.deltaTime; if (Networking.IsOwner(this.gameObject)) { time += Time.deltaTime; if (time >= 2.0f) { time = 0.0f; SetNowPlayerID(); SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "SetDisplayName"); } //matInter.SetColor("_Color", Color.green); } else { matInter.SetColor("_Color", Color.red); } } else if (gamestate == 1) //開始前のカウントダウン { totalTime += Time.deltaTime; if (totalTime >= 2.998f) { if (Networking.IsOwner(this.gameObject)) { SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "SetNextState"); SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "ResetAllTime"); } } } else if (gamestate == 2) //ゲーム中 { totalTime += Time.deltaTime; //Ownerの手にのみColliderを追従させる if (Networking.IsOwner(this.gameObject)) { var cubepos = localplayer.GetBonePosition(HumanBodyBones.RightIndexDistal); collidercube.transform.position = cubepos; } if (isJamp) { time += Time.deltaTime; height = Mathf.Sin(mypow(PI * time, 0.8f)); height = mypow(height, 1.0f) * 0.5f; campos.y = y + height * 0.3f; judgecam.transform.position = campos; if (height < 0.0) { JumpStateFalse(); } } matdisplay.SetFloat("_Jump", height); } else if (gamestate == 3) //ゲームオーバー { time += Time.deltaTime; if (isSetRanking == false) { if (time >= 3.0f) { SortRanking(); SetRanking(); isSetRanking = true; totalTime = nowTime; } } if (Networking.IsOwner(this.gameObject)) { if (isSetRanking & time >= 2.0f) { time = 0.0f; SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "SetDisplayName"); } } } matdisplay.SetFloat("_TotalTime", totalTime); }
void Update() { // XXX sometimes this script fails to track the owner's hand, I think it throws an exception // try waiting a few seconds until after the map loads, in case there's some initialization that // this races against to actually succeed, either GetBonePosition or Networking.IsOwner if ((Time.time - startTime) < 3f) { return; } if (isInEditor) { return; } if (Networking.IsOwner(gameObject)) { Vector3 center; if (hand == HumanBodyBones.LeftHand) { center = player.GetBonePosition(HumanBodyBones.LeftHand); center += fingerWeight[0] * player.GetBonePosition(HumanBodyBones.LeftThumbProximal); center += fingerWeight[1] * player.GetBonePosition(HumanBodyBones.LeftThumbIntermediate); center += fingerWeight[2] * player.GetBonePosition(HumanBodyBones.LeftThumbDistal); center += fingerWeight[3] * player.GetBonePosition(HumanBodyBones.LeftIndexProximal); center += fingerWeight[4] * player.GetBonePosition(HumanBodyBones.LeftIndexIntermediate); center += fingerWeight[5] * player.GetBonePosition(HumanBodyBones.LeftIndexDistal); center += fingerWeight[6] * player.GetBonePosition(HumanBodyBones.LeftMiddleProximal); center += fingerWeight[7] * player.GetBonePosition(HumanBodyBones.LeftMiddleIntermediate); center += fingerWeight[8] * player.GetBonePosition(HumanBodyBones.LeftMiddleDistal); center += fingerWeight[9] * player.GetBonePosition(HumanBodyBones.LeftRingProximal); center += fingerWeight[10] * player.GetBonePosition(HumanBodyBones.LeftRingIntermediate); center += fingerWeight[11] * player.GetBonePosition(HumanBodyBones.LeftRingDistal); center += fingerWeight[12] * player.GetBonePosition(HumanBodyBones.LeftLittleProximal); center += fingerWeight[13] * player.GetBonePosition(HumanBodyBones.LeftLittleIntermediate); center += fingerWeight[14] * player.GetBonePosition(HumanBodyBones.LeftLittleDistal); center = center / (1 + totalFingerWeight); } else { center = player.GetBonePosition(HumanBodyBones.RightHand); center += fingerWeight[0] * player.GetBonePosition(HumanBodyBones.RightThumbProximal); center += fingerWeight[1] * player.GetBonePosition(HumanBodyBones.RightThumbIntermediate); center += fingerWeight[2] * player.GetBonePosition(HumanBodyBones.RightThumbDistal); center += fingerWeight[3] * player.GetBonePosition(HumanBodyBones.RightIndexProximal); center += fingerWeight[4] * player.GetBonePosition(HumanBodyBones.RightIndexIntermediate); center += fingerWeight[5] * player.GetBonePosition(HumanBodyBones.RightIndexDistal); center += fingerWeight[6] * player.GetBonePosition(HumanBodyBones.RightMiddleProximal); center += fingerWeight[7] * player.GetBonePosition(HumanBodyBones.RightMiddleIntermediate); center += fingerWeight[8] * player.GetBonePosition(HumanBodyBones.RightMiddleDistal); center += fingerWeight[9] * player.GetBonePosition(HumanBodyBones.RightRingProximal); center += fingerWeight[10] * player.GetBonePosition(HumanBodyBones.RightRingIntermediate); center += fingerWeight[11] * player.GetBonePosition(HumanBodyBones.RightRingDistal); center += fingerWeight[12] * player.GetBonePosition(HumanBodyBones.RightLittleProximal); center += fingerWeight[13] * player.GetBonePosition(HumanBodyBones.RightLittleIntermediate); center += fingerWeight[14] * player.GetBonePosition(HumanBodyBones.RightLittleDistal); center = center / (1 + totalFingerWeight); } transform.position = center; } }