Пример #1
0
        //-------------------------------------------------
        protected virtual void OnHandHoverBegin(Hand hand)
        {
            bool showHint = false;

            // "Catch" the throwable by holding down the interaction button instead of pressing it.
            // Only do this if the throwable is moving faster than the prescribed threshold speed,
            // and if it isn't attached to another hand
            if (!attached && catchingSpeedThreshold != -1)
            {
                float catchingThreshold = catchingSpeedThreshold * SteamVR_Utils.GetLossyScale(Player.instance.trackingOriginTransform);

                GrabTypes bestGrabType = hand.GetBestGrabbingType();

                if (bestGrabType != GrabTypes.None)
                {
                    if (rigidbody.velocity.magnitude >= catchingThreshold)
                    {
                        hand.AttachObject(gameObject, bestGrabType, attachmentFlags);
                        showHint = false;
                    }
                }
            }

            if (showHint)
            {
                hand.ShowGrabHint();
            }
        }
Пример #2
0
        //-------------------------------------------------
        private void Pulse()
        {
            if (hand && (hand.isActive) && (hand.GetBestGrabbingType() != GrabTypes.None))
            {
                ushort duration = (ushort)Random.Range(minimumPulseDuration, maximumPulseDuration + 1);
                hand.TriggerHapticPulse(duration);

                onPulse.Invoke();
            }
        }
Пример #3
0
        //-------------------------------------------------
        private void HandHoverUpdate(Hand hand)
        {
            //Debug.Log(hand.gameObject.name + " Hover Update");

            GrabTypes startingGrabType = hand.GetGrabStarting();
            bool      isGrabStarting   = startingGrabType != GrabTypes.None;
            bool      isGrabbing       = hand.IsGrabbing();
            bool      isGrabEnding     = hand.IsGrabbingWithType(grabbedWithType) == false;


            if (isGrabStarting || (grabbingHand == null && isGrabbing))               // Grab Start
            //Debug.Log("    Grab Start! (" + Time.frameCount + ")");
            //if (grabbingHand != null) { // Another hand has already grabbed -> switch hands
            //	Debug.Log("    (switching hands)");
            //}

            {
                lastHandProjected = ComputeToTransformProjected(hand.hoverSphereTransform);

                if (hoverLock)
                {
                    hand.HoverLock(interactable);
                    handHoverLocked = hand;
                }

                driving         = true;
                grabbedWithType = hand.GetBestGrabbingType(GrabTypes.Grip);
                grabbingHand    = hand;
                isGrabEnding    = false;
            }
            else if (isGrabEnding && grabbingHand == hand)                 // Grab End
            //Debug.Log("    Grab End! (" + Time.frameCount + ")");

            {
                if (hoverLock)
                {
                    hand.HoverUnlock(interactable);
                    handHoverLocked = null;
                }

                driving         = false;
                grabbedWithType = GrabTypes.None;
                grabbingHand    = null;
            }

            if (grabbingHand == hand)
            {
                //Debug.Log("    Grab Update!");
                ComputeAngle(hand);
                UpdateAll();
            }
        }
Пример #4
0
        //-------------------------------------------------
        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();
            }

            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)
                    {
                        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
            }
        }
Пример #5
0
        // -----------------------------------
        // Obsolete methods for altering pitch based on y-axis displacement.
        // will be removed in future updates
        // -----------------------------------

        /*protected float GetVerticalDisplaceScalar(Vector3 startingPos, Vector3 updatedPos)
         * {
         *  var verticalDisplacement = updatedPos.y - startingPos.y / updatedPos.y;
         *  return verticalDisplacement;
         * }
         *
         * protected void ModifyPitchBasedOnVerticalVectorDisplacement(float verticalDisplacement, bool enablePitchModify)
         * {
         *  if (enablePitchModify)
         *  {
         *      audioSource.pitch = defaultPitch + verticalDisplacement * pitchModifier;
         *  }
         * }
         *
         * protected void UpdateStationaryPosition(Vector3 updatePosition)
         * {
         *  stationaryPosition = updatePosition;
         * }*/

        protected virtual void OnHandHoverBegin(Hand hand)
        {
            GrabTypes bestGrabType = hand.GetBestGrabbingType();
        }