//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(VRTRIXGloveGrab hand) { //Debug.Log(VRTRIXGloveVRInteraction.GetGesture(hand.GetHandType())); if (hand.GetStandardInteractionButtonDown()) { if (hand.currentAttachedObject != gameObject) { isHoveredbyHand = true; //Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock(GetComponent <VRTRIXInteractable>()); if (hand.GetHandType() == HANDTYPE.LEFT_HAND) { // Attach this object to the left hand //hand.AttachObject(gameObject, attachmentFlags); hand.AttachLongBow(gameObject, attachmentFlags, "L_Middle_1"); gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f); gameObject.transform.localRotation = Quaternion.Euler(0, 200f, 90f); } else if (hand.GetHandType() == HANDTYPE.RIGHT_HAND) { hand.AttachLongBow(gameObject, attachmentFlags, "R_Middle_1"); gameObject.transform.localPosition = new Vector3(-0.311f, 0.072f, 0.04f); gameObject.transform.localRotation = Quaternion.Euler(0, -20f, -90f); } } } }
//------------------------------------------------- private void HandHoverUpdate(VRTRIXGloveGrab hand) { //Trigger got pressed //Debug.Log(hand.GetStandardInteractionButtonDown()); if (hand.GetStandardInteractionButtonDown()) { hand.AttachObject(gameObject, attachmentFlags, attachmentPoint); //ControllerButtonHints.HideButtonHint(hand, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); } }
//------------------------------------------------- private void HandHoverUpdate(VRTRIXGloveGrab hand) { if (requireTriggerPressToTake) { if (hand.GetStandardInteractionButtonDown()) { SpawnAndAttachObject(hand); } } }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(VRTRIXGloveGrab hand) { //Debug.Log(VRTRIXGloveVRInteraction.GetGesture(hand.GetHandType())); if (hand.GetStandardInteractionButtonDown()) { if (hand.currentAttachedObject != gameObject) { // Save our position/rotation so that we can restore it when we detach oldPosition = transform.position; oldRotation = transform.rotation; //Call this to continue receiving HandHoverUpdate messages, // and prevent the hand from hovering over anything else hand.HoverLock(GetComponent <VRTRIXInteractable>()); // Attach this object to the hand hand.AttachObject(gameObject, attachmentFlags); } } }
//------------------------------------------------- private void HandAttachedUpdate(VRTRIXGloveGrab 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(); } 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.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.GetStandardInteractionButtonDown() && !nocked) { if (currentArrow == null) { currentArrow = InstantiateArrow(); } nocked = true; bow.StartNock(this); hand.HoverLock(GetComponent <VRTRIXInteractable>()); 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.GetStandardInteractionButtonDown())) { 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 <VRTRIXInteractable>()); allowTeleport.teleportAllowed = true; } bow.StartRotationLerp(); // Arrow is releasing from the bow, tell the bow to lerp back to controller rotation } }