private void OnCollisionEnter(Collision collision) { bool touchingDynamic = false; if (collision.rigidbody != null) { if (collision.rigidbody.isKinematic == false) { touchingDynamic = true; } } // low friction if touching static object, high friction if touching dynamic SetPhysicMaterial(touchingDynamic ? physicMaterial_highfriction : physicMaterial_lowfriction); float energy = collision.relativeVelocity.magnitude; if (energy > minCollisionEnergy && Time.time - lastCollisionHapticsTime > minCollisionHapticsTime) { lastCollisionHapticsTime = Time.time; float intensity = Util.RemapNumber(energy, minCollisionEnergy, maxCollisionEnergy, 0.3f, 1.0f); float length = Util.RemapNumber(energy, minCollisionEnergy, maxCollisionEnergy, 0.0f, 0.06f); hand.hand.TriggerHapticPulse(length, 100, intensity); } }
//------------------------------------------------- private void OnCollisionEnter(Collision collision) { if (bParticlesSpawned) { return; } Hand collisionParentHand = null; BalloonHapticBump balloonColliderScript = collision.gameObject.GetComponent <BalloonHapticBump>(); if (balloonColliderScript != null && balloonColliderScript.physParent != null) { collisionParentHand = balloonColliderScript.physParent.GetComponentInParent <Hand>(); } if (Time.time > (lastSoundTime + soundDelay)) { if (collisionParentHand != null) // If the collision was with a controller { if (Time.time > (releaseTime + soundDelay)) // Only play sound if it's not immediately after release { collisionSound.Play(); lastSoundTime = Time.time; } } else // Collision was not with a controller, play sound { collisionSound.Play(); lastSoundTime = Time.time; } } if (destructTime > 0) // Balloon is released away from the controller, don't do the haptic stuff that follows { return; } if (balloonRigidbody.velocity.magnitude > (maxVelocity * 10)) { balloonRigidbody.velocity = balloonRigidbody.velocity.normalized * maxVelocity; } if (hand != null) { ushort collisionStrength = (ushort)Mathf.Clamp(Util.RemapNumber(collision.relativeVelocity.magnitude, 0f, 3f, 500f, 800f), 500f, 800f); hand.controller.TriggerHapticPulse(collisionStrength); } }
private void OnCollisionEnter(Collision collision) { if (this.bParticlesSpawned) { return; } Hand x = null; BalloonHapticBump component = collision.gameObject.GetComponent <BalloonHapticBump>(); if (component != null && component.physParent != null) { x = component.physParent.GetComponentInParent <Hand>(); } if (Time.time > this.lastSoundTime + this.soundDelay) { if (x != null) { if (Time.time > this.releaseTime + this.soundDelay) { this.collisionSound.Play(); this.lastSoundTime = Time.time; } } else { this.collisionSound.Play(); this.lastSoundTime = Time.time; } } if (this.destructTime > 0f) { return; } if (this.balloonRigidbody.velocity.magnitude > this.maxVelocity * 10f) { this.balloonRigidbody.velocity = this.balloonRigidbody.velocity.normalized * this.maxVelocity; } if (this.hand != null) { ushort durationMicroSec = (ushort)Mathf.Clamp(Util.RemapNumber(collision.relativeVelocity.magnitude, 0f, 3f, 500f, 800f), 500f, 800f); this.hand.controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0); } }
private void OnCollisionEnter(Collision collision) { bool touchingDynamic = false; if (collision.rigidbody != null) { if (collision.rigidbody.isKinematic == false) { touchingDynamic = true; } } // low friction if touching static object, high friction if touching dynamic SetPhysicMaterial(touchingDynamic ? physicMaterial_highfriction : physicMaterial_lowfriction); float energy = collision.relativeVelocity.magnitude; if (energy > minCollisionEnergy && Time.time - lastCollisionHapticsTime > minCollisionHapticsTime) { lastCollisionHapticsTime = Time.time; float intensity = Util.RemapNumber(energy, minCollisionEnergy, maxCollisionEnergy, 0.3f, 1.0f); float length = Util.RemapNumber(energy, minCollisionEnergy, maxCollisionEnergy, 0.0f, 0.06f); // Debug.Log("Haptic trigger: " + collision.gameObject.name, this); if (!AppData.IsIgnorableHaptic(collision.gameObject.name)) { hand.hand.TriggerHapticPulse(length, 100, intensity); } // else // Debug.Log("Ignored haptic", this); } }
//------------------------------------------------- private void HandAttachedUpdate(Hand hand) { if (bow == null) { FindBow(); } if (bow == null) { return; } if (allowArrowSpawn && (currentArrow == null)) // If we're allowed to have an active arrow in hand but don't yet, spawn one { currentArrow = InstantiateArrow(); arrowSpawnSound.Play(); } var distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position); // If there's an arrow spawned in the hand and it's not nocked yet if (!nocked) { // If we're close enough to nock position that we want to start arrow rotation lerp, do so if (distanceToNockPosition < rotationLerpThreshold) { var lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1); arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp); } else // Not close enough for rotation lerp, reset rotation { arrowNockTransform.localRotation = Quaternion.identity; } // If we're close enough to the nock position that we want to start arrow position lerp, do so if (distanceToNockPosition < positionLerpThreshold) { var posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1); posLerp = Mathf.Clamp(posLerp, 0f, 1f); arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp); } else // Not close enough for position lerp, reset position { arrowNockTransform.position = arrowNockTransform.parent.position; } // Give a haptic tick when lerp is visually complete if (distanceToNockPosition < lerpCompleteDistance) { if (!arrowLerpComplete) { arrowLerpComplete = true; hand.controller.TriggerHapticPulse(500); } } else { if (arrowLerpComplete) { arrowLerpComplete = false; } } // Allow nocking the arrow when controller is close enough if (distanceToNockPosition < nockDistance) { if (!inNockRange) { inNockRange = true; bow.ArrowInPosition(); } } else { if (inNockRange) { inNockRange = false; } } // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock if ((distanceToNockPosition < nockDistance) && hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) && !nocked) { if (currentArrow == null) { currentArrow = InstantiateArrow(); } nocked = true; bow.StartNock(this); hand.HoverLock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = false; currentArrow.transform.parent = bow.nockTransform; Util.ResetTransform(currentArrow.transform); Util.ResetTransform(arrowNockTransform); } } // If arrow is nocked, and we release the trigger if (nocked && (!hand.controller.GetPress(SteamVR_Controller.ButtonMask.Trigger) || hand.controller.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))) { if (bow.pulled) // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand { FireArrow(); } else { arrowNockTransform.rotation = currentArrow.transform.rotation; currentArrow.transform.parent = arrowNockTransform; Util.ResetTransform(currentArrow.transform); nocked = false; bow.ReleaseNock(); hand.HoverUnlock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = true; } bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation } }
//------------------------------------------------- private void HandAttachedUpdate(Hand hand) { // Reset transform since we cheated it right after getting poses on previous frame //transform.localPosition = Vector3.zero; //transform.localRotation = Quaternion.identity; // Update handedness guess EvaluateHandedness(); if (nocked) { Vector3 nockToarrowHand = (arrowHand.arrowNockTransform.parent.position - nockRestTransform.position); // Vector from bow nock transform to arrowhand nock transform - used to align bow when drawing // Align bow // Time lerp value used for ramping into drawn bow orientation float lerp = Util.RemapNumberClamped(Time.time, nockLerpStartTime, (nockLerpStartTime + lerpDuration), 0f, 1f); float pullLerp = Util.RemapNumberClamped(nockToarrowHand.magnitude, minPull, maxPull, 0f, 1f); // Normalized current state of bow draw 0 - 1 Vector3 arrowNockTransformToHeadset = ((Player.instance.hmdTransform.position + (Vector3.down * 0.05f)) - arrowHand.arrowNockTransform.parent.position).normalized; Vector3 arrowHandPosition = (arrowHand.arrowNockTransform.parent.position + ((arrowNockTransformToHeadset * drawOffset) * pullLerp)); // Use this line to lerp arrowHand nock position //Vector3 arrowHandPosition = arrowHand.arrowNockTransform.position; // Use this line if we don't want to lerp arrowHand nock position Vector3 pivotToString = (arrowHandPosition - pivotTransform.position).normalized; Vector3 pivotToLowerHandle = (handleTransform.position - pivotTransform.position).normalized; bowLeftVector = -Vector3.Cross(pivotToLowerHandle, pivotToString); pivotTransform.rotation = Quaternion.Lerp(nockLerpStartRotation, Quaternion.LookRotation(pivotToString, bowLeftVector), lerp); // Move nock position if (Vector3.Dot(nockToarrowHand, -nockTransform.forward) > 0) { float distanceToarrowHand = nockToarrowHand.magnitude * lerp; nockTransform.localPosition = new Vector3(0f, 0f, Mathf.Clamp(-distanceToarrowHand, -maxPull, 0f)); nockDistanceTravelled = -nockTransform.localPosition.z; arrowVelocity = Util.RemapNumber(nockDistanceTravelled, minPull, maxPull, arrowMinVelocity, arrowMaxVelocity); drawTension = Util.RemapNumberClamped(nockDistanceTravelled, 0, maxPull, 0f, 1f); this.bowDrawLinearMapping.value = drawTension; // Send drawTension value to LinearMapping script, which drives the bow draw animation if (nockDistanceTravelled > minPull) { pulled = true; } else { pulled = false; } if ((nockDistanceTravelled > (lastTickDistance + hapticDistanceThreshold)) || nockDistanceTravelled < (lastTickDistance - hapticDistanceThreshold)) { ushort hapticStrength = (ushort)Util.RemapNumber(nockDistanceTravelled, 0, maxPull, bowPullPulseStrengthLow, bowPullPulseStrengthHigh); hand.TriggerHapticPulse(hapticStrength); hand.otherHand.TriggerHapticPulse(hapticStrength); drawSound.PlayBowTensionClicks(drawTension); lastTickDistance = nockDistanceTravelled; } if (nockDistanceTravelled >= maxPull) { if (Time.time > nextStrainTick) { hand.TriggerHapticPulse(400); hand.otherHand.TriggerHapticPulse(400); drawSound.PlayBowTensionClicks(drawTension); nextStrainTick = Time.time + Random.Range(minStrainTickTime, maxStrainTickTime); } } } else { nockTransform.localPosition = new Vector3(0f, 0f, 0f); this.bowDrawLinearMapping.value = 0f; } } else { if (lerpBackToZeroRotation) { float lerp = Util.RemapNumber(Time.time, lerpStartTime, lerpStartTime + lerpDuration, 0, 1); pivotTransform.localRotation = Quaternion.Lerp(lerpStartRotation, Quaternion.identity, lerp); if (lerp >= 1) { lerpBackToZeroRotation = false; } } } }
// Token: 0x06005DD3 RID: 24019 RVA: 0x0020D2D8 File Offset: 0x0020B6D8 private void HandAttachedUpdate(Hand hand) { base.transform.localPosition = Vector3.zero; base.transform.localRotation = Quaternion.identity; this.EvaluateHandedness(); if (this.nocked) { this.deferNewPoses = true; Vector3 lhs = this.arrowHand.arrowNockTransform.parent.position - this.nockRestTransform.position; float num = Util.RemapNumberClamped(Time.time, this.nockLerpStartTime, this.nockLerpStartTime + this.lerpDuration, 0f, 1f); float d = Util.RemapNumberClamped(lhs.magnitude, 0.05f, 0.5f, 0f, 1f); Vector3 normalized = (Player.instance.hmdTransform.position + Vector3.down * 0.05f - this.arrowHand.arrowNockTransform.parent.position).normalized; Vector3 a = this.arrowHand.arrowNockTransform.parent.position + normalized * this.drawOffset * d; Vector3 normalized2 = (a - this.pivotTransform.position).normalized; Vector3 normalized3 = (this.handleTransform.position - this.pivotTransform.position).normalized; this.bowLeftVector = -Vector3.Cross(normalized3, normalized2); this.pivotTransform.rotation = Quaternion.Lerp(this.nockLerpStartRotation, Quaternion.LookRotation(normalized2, this.bowLeftVector), num); if (Vector3.Dot(lhs, -this.nockTransform.forward) > 0f) { float num2 = lhs.magnitude * num; this.nockTransform.localPosition = new Vector3(0f, 0f, Mathf.Clamp(-num2, -0.5f, 0f)); this.nockDistanceTravelled = -this.nockTransform.localPosition.z; this.arrowVelocity = Util.RemapNumber(this.nockDistanceTravelled, 0.05f, 0.5f, this.arrowMinVelocity, this.arrowMaxVelocity); this.drawTension = Util.RemapNumberClamped(this.nockDistanceTravelled, 0f, 0.5f, 0f, 1f); this.bowDrawLinearMapping.value = this.drawTension; if (this.nockDistanceTravelled > 0.05f) { this.pulled = true; } else { this.pulled = false; } if (this.nockDistanceTravelled > this.lastTickDistance + this.hapticDistanceThreshold || this.nockDistanceTravelled < this.lastTickDistance - this.hapticDistanceThreshold) { ushort durationMicroSec = (ushort)Util.RemapNumber(this.nockDistanceTravelled, 0f, 0.5f, 100f, 500f); hand.controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0); hand.otherHand.controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0); this.drawSound.PlayBowTensionClicks(this.drawTension); this.lastTickDistance = this.nockDistanceTravelled; } if (this.nockDistanceTravelled >= 0.5f && Time.time > this.nextStrainTick) { hand.controller.TriggerHapticPulse(400, EVRButtonId.k_EButton_Axis0); hand.otherHand.controller.TriggerHapticPulse(400, EVRButtonId.k_EButton_Axis0); this.drawSound.PlayBowTensionClicks(this.drawTension); this.nextStrainTick = Time.time + UnityEngine.Random.Range(this.minStrainTickTime, this.maxStrainTickTime); } } else { this.nockTransform.localPosition = new Vector3(0f, 0f, 0f); this.bowDrawLinearMapping.value = 0f; } } else if (this.lerpBackToZeroRotation) { float num3 = Util.RemapNumber(Time.time, this.lerpStartTime, this.lerpStartTime + this.lerpDuration, 0f, 1f); this.pivotTransform.localRotation = Quaternion.Lerp(this.lerpStartRotation, Quaternion.identity, num3); if (num3 >= 1f) { this.lerpBackToZeroRotation = false; } } }
public static float RemapNumberClamped(float num, float low1, float high1, float low2, float high2) { return(Mathf.Clamp(Util.RemapNumber(num, low1, high1, low2, high2), Mathf.Min(low2, high2), Mathf.Max(low2, high2))); }
private void HandAttachedUpdate(Hand hand) { if (this.bow == null) { this.FindBow(); } if (this.bow == null) { return; } if (this.allowArrowSpawn && this.currentArrow == null) { this.currentArrow = this.InstantiateArrow(); this.arrowSpawnSound.Play(); } float num = Vector3.Distance(base.transform.parent.position, this.bow.nockTransform.position); if (!this.nocked) { if (num < this.rotationLerpThreshold) { float t = Util.RemapNumber(num, this.rotationLerpThreshold, this.lerpCompleteDistance, 0f, 1f); this.arrowNockTransform.rotation = Quaternion.Lerp(this.arrowNockTransform.parent.rotation, this.bow.nockRestTransform.rotation, t); } else { this.arrowNockTransform.localRotation = Quaternion.identity; } if (num < this.positionLerpThreshold) { float num2 = Util.RemapNumber(num, this.positionLerpThreshold, this.lerpCompleteDistance, 0f, 1f); num2 = Mathf.Clamp(num2, 0f, 1f); this.arrowNockTransform.position = Vector3.Lerp(this.arrowNockTransform.parent.position, this.bow.nockRestTransform.position, num2); } else { this.arrowNockTransform.position = this.arrowNockTransform.parent.position; } if (num < this.lerpCompleteDistance) { if (!this.arrowLerpComplete) { this.arrowLerpComplete = true; hand.controller.TriggerHapticPulse(500, EVRButtonId.k_EButton_Axis0); } } else if (this.arrowLerpComplete) { this.arrowLerpComplete = false; } if (num < this.nockDistance) { if (!this.inNockRange) { this.inNockRange = true; this.bow.ArrowInPosition(); } } else if (this.inNockRange) { this.inNockRange = false; } if (num < this.nockDistance && hand.controller.GetPress(8589934592UL) && !this.nocked) { if (this.currentArrow == null) { this.currentArrow = this.InstantiateArrow(); } this.nocked = true; this.bow.StartNock(this); hand.HoverLock(base.GetComponent <Interactable>()); this.allowTeleport.teleportAllowed = false; this.currentArrow.transform.parent = this.bow.nockTransform; Util.ResetTransform(this.currentArrow.transform, true); Util.ResetTransform(this.arrowNockTransform, true); } } if (this.nocked && (!hand.controller.GetPress(8589934592UL) || hand.controller.GetPressUp(8589934592UL))) { if (this.bow.pulled) { this.FireArrow(); } else { this.arrowNockTransform.rotation = this.currentArrow.transform.rotation; this.currentArrow.transform.parent = this.arrowNockTransform; Util.ResetTransform(this.currentArrow.transform, true); this.nocked = false; this.bow.ReleaseNock(); hand.HoverUnlock(base.GetComponent <Interactable>()); this.allowTeleport.teleportAllowed = true; } this.bow.StartRotationLerp(); } }
public void OnEquippedUpdate(Inventory inventory) { if (arrowHand == null) { FindArrowHand(inventory); } if (arrowHand == null) { return; } if (arrowHand.allowArrowSpawn && (arrowHand.currentArrow == null)) // If we're allowed to have an active arrow in hand but don't yet, spawn one { arrowHand.currentArrow = InstantiateArrow(); arrowHand.arrowSpawnSound.Play(); } // Reset transform since we cheated it right after getting poses on previous frame //transform.localPosition = Vector3.zero; //transform.localRotation = Quaternion.identity; // Update handedness guess EvaluateHandedness(); HandleNockPositioning(arrowHand.GetComponent <Item>().myEquipPoint); // inventory.otherInventory); if (nocked) { Vector3 arrowNockTransformParentPos = arrowHand.arrowNockTransform.parent.position; // Vector from bow nock transform to arrowhand nock transform - used to align bow when drawing Vector3 nockToarrowHand = (arrowNockTransformParentPos - nockRestTransform.position); float nockToArrowHandLength = nockToarrowHand.magnitude; // Align bow // Time lerp value used for ramping into drawn bow orientation float lerp = Util.RemapNumberClamped(Time.time, nockLerpStartTime, (nockLerpStartTime + lerpDuration), 0f, 1f); // Normalized current state of bow draw 0 - 1 float pullLerp = Util.RemapNumberClamped(nockToArrowHandLength, minPull, maxPull, 0f, 1f); Vector3 arrowNockTransformToHeadset = ((Player.instance.hmdTransform.position + (Vector3.down * 0.05f)) - arrowNockTransformParentPos).normalized; // Use this line to lerp arrowHand nock position Vector3 arrowHandPosition = (arrowNockTransformParentPos + ((arrowNockTransformToHeadset * drawOffset) * pullLerp)); // Use this line if we don't want to lerp arrowHand nock position //Vector3 arrowHandPosition = arrowNockTransform.position; Vector3 pivotToString = (arrowHandPosition - pivotTransform.position).normalized; Vector3 pivotToLowerHandle = (handleTransform.position - pivotTransform.position).normalized; Vector3 bowLeftVector = -Vector3.Cross(pivotToLowerHandle, pivotToString); pivotTransform.rotation = Quaternion.Lerp(nockLerpStartRotation, Quaternion.LookRotation(pivotToString, bowLeftVector), lerp); // Move nock position if (Vector3.Dot(nockToarrowHand, -nockTransform.forward) > 0) { float distanceToarrowHand = nockToArrowHandLength * lerp; float zOffset = Mathf.Clamp(-distanceToarrowHand, -maxPull, 0f); nockTransform.localPosition = new Vector3(0f, 0f, zOffset); float nockDistanceTravelled = -zOffset; arrowVelocity = Util.RemapNumber(nockDistanceTravelled, minPull, maxPull, arrowMinVelocity, arrowMaxVelocity); drawTension = Util.RemapNumberClamped(nockDistanceTravelled, 0, maxPull, 0f, 1f); // Send drawTension value to LinearMapping script, which drives the bow draw animation this.bowDrawLinearMapping.value = drawTension; pulled = (nockDistanceTravelled > minPull); HandleNockedEffects(nockDistanceTravelled, drawTension); } else { nockTransform.localPosition = new Vector3(0f, 0f, 0f); this.bowDrawLinearMapping.value = 0f; } } else { if (lerpBackToZeroRotation) { if (HandleLerpBackToRotationAfterArrowRelease()) { lerpBackToZeroRotation = false; } } } }
//------------------------------------------------- private void HandAttachedUpdate(Hand hand) { if (_bow == null) { FindBow(); } if (_bow == null) { return; } if (allowArrowSpawn && (_currentArrow == null)) // If we're allowed to have an active arrow in hand but don't yet, spawn one { InstantiateAndSetArrow(); arrowSpawnSound.Play(); } float distanceToNockPosition = Vector3.Distance(transform.parent.position, _bow.nockTransform.position); // If there's an arrow spawned in the hand and it's not nocked yet if (!nocked) { // If we're close enough to nock position that we want to start arrow rotation lerp, do so if (distanceToNockPosition < rotationLerpThreshold) { float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1); ArrowNockTransform.rotation = Quaternion.Lerp(ArrowNockTransform.parent.rotation, _bow.nockRestTransform.rotation, lerp); } else // Not close enough for rotation lerp, reset rotation { ArrowNockTransform.localRotation = Quaternion.identity; } // If we're close enough to the nock position that we want to start arrow position lerp, do so if (distanceToNockPosition < positionLerpThreshold) { float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1); posLerp = Mathf.Clamp(posLerp, 0f, 1f); ArrowNockTransform.position = Vector3.Lerp(ArrowNockTransform.parent.position, _bow.nockRestTransform.position, posLerp); } else // Not close enough for position lerp, reset position { ArrowNockTransform.position = ArrowNockTransform.parent.position; } // Give a haptic tick when lerp is visually complete if (distanceToNockPosition < lerpCompleteDistance) { if (!arrowLerpComplete) { arrowLerpComplete = true; hand.TriggerHapticPulse(500); } } else if (arrowLerpComplete) { arrowLerpComplete = false; } // Allow nocking the arrow when controller is close enough if (distanceToNockPosition < nockDistance) { if (!inNockRange) { inNockRange = true; _bow.ArrowInPosition(); } } else if (inNockRange) { inNockRange = false; } GrabTypes bestGrab = hand.GetBestGrabbingType(GrabTypes.Pinch, true); // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock if ((distanceToNockPosition < nockDistance) && bestGrab != GrabTypes.None && !nocked) { if (_currentArrow == null) { InstantiateAndSetArrow(); } nocked = true; nockedWithType = bestGrab; _bow.StartNock(this); hand.HoverLock(GetComponent <Interactable>()); _currentArrow.transform.parent = _bow.nockTransform; Util.ResetTransform(_currentArrow.transform); Util.ResetTransform(ArrowNockTransform); } } if (_currentArrowCmpt != null) { _currentArrowCmpt.Charging = nocked && _bow.pulled; } // If arrow is nocked, and we release the trigger if (nocked) { if (hand.IsGrabbingWithType(nockedWithType) == false) { if (_bow.pulled) // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand { FireArrow(); } else { ArrowNockTransform.rotation = _currentArrow.transform.rotation; _currentArrow.transform.parent = ArrowNockTransform; Util.ResetTransform(_currentArrow.transform); nocked = false; nockedWithType = GrabTypes.None; _bow.ReleaseNock(); hand.HoverUnlock(GetComponent <Interactable>()); } _bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation } } }
//------------------------------------------------- private void HandAttachedUpdate(Hand hand) { //quiver.GetComponent<Quiver>(). //Debug.Log("update"); if (bow == null) { FindBow(); } if (bow == null) { return; } float distanceToNockPosition = Vector3.Distance(transform.parent.position, bow.nockTransform.position); int quiverType = quiverSelection.GetComponent <Dropdown>().value + 1; switch (quiverType) { case 1: quiver = GameObject.Find("Quiver (Neck)"); break; case 2: quiver = GameObject.Find("Quiver (Shoulder)"); break; case 3: quiver = GameObject.Find("Quiver (Chest)"); break; default: print("Oops"); break; } noQuiver = quiverEnable.GetComponent <Toggle>().isOn; if (allowArrowSpawn && (currentArrow == null) && ((noQuiver || quiver.GetComponent <Interactable>().isHovering))) // If we're allowed to have an active arrow in hand but don't yet, spawn one { currentArrow = InstantiateArrow(); arrowSpawnSound.Play(); hand.TriggerHapticPulse(5000); } // If there's an arrow spawned in the hand and it's not nocked yet else if ((currentArrow != null) && !nocked) { // If we're close enough to nock position that we want to start arrow rotation lerp, do so if (distanceToNockPosition < rotationLerpThreshold) { float lerp = Util.RemapNumber(distanceToNockPosition, rotationLerpThreshold, lerpCompleteDistance, 0, 1); arrowNockTransform.rotation = Quaternion.Lerp(arrowNockTransform.parent.rotation, bow.nockRestTransform.rotation, lerp); } else // Not close enough for rotation lerp, reset rotation { arrowNockTransform.localRotation = Quaternion.identity; } // If we're close enough to the nock position that we want to start arrow position lerp, do so if (distanceToNockPosition < positionLerpThreshold) { float posLerp = Util.RemapNumber(distanceToNockPosition, positionLerpThreshold, lerpCompleteDistance, 0, 1); posLerp = Mathf.Clamp(posLerp, 0f, 1f); arrowNockTransform.position = Vector3.Lerp(arrowNockTransform.parent.position, bow.nockRestTransform.position, posLerp); } else // Not close enough for position lerp, reset position { arrowNockTransform.position = arrowNockTransform.parent.position; } // Give a haptic tick when lerp is visually complete if (distanceToNockPosition < lerpCompleteDistance) { if (!arrowLerpComplete) { arrowLerpComplete = true; hand.TriggerHapticPulse(500); } } else { if (arrowLerpComplete) { arrowLerpComplete = false; } } // Allow nocking the arrow when controller is close enough if (distanceToNockPosition < nockDistance) { if (!inNockRange) { inNockRange = true; bow.ArrowInPosition(); } } else { if (inNockRange) { inNockRange = false; } } GrabTypes bestGrab = hand.GetBestGrabbingType(GrabTypes.Pinch, true); // If arrow is close enough to the nock position and we're pressing the trigger, and we're not nocked yet, Nock if ((distanceToNockPosition < nockDistance) && bestGrab != GrabTypes.None && !nocked) { if (currentArrow == null) { currentArrow = InstantiateArrow(); } nocked = true; nockedWithType = bestGrab; bow.StartNock(this); hand.HoverLock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = false; currentArrow.transform.parent = bow.nockTransform; Util.ResetTransform(currentArrow.transform); Util.ResetTransform(arrowNockTransform); } } // If arrow is nocked, and we release the trigger if (nocked && hand.IsGrabbingWithType(nockedWithType) == false) { if (bow.pulled) // If bow is pulled back far enough, fire arrow, otherwise reset arrow in arrowhand { FireArrow(); } else { arrowNockTransform.rotation = currentArrow.transform.rotation; currentArrow.transform.parent = arrowNockTransform; Util.ResetTransform(currentArrow.transform); nocked = false; nockedWithType = GrabTypes.None; bow.ReleaseNock(); hand.HoverUnlock(GetComponent <Interactable>()); allowTeleport.teleportAllowed = true; } bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation } }