Esempio n. 1
0
        void Update()
        {
            // holding this object
            if (dummyGrabbable != null && currentGrabber != null)
            {
                // Do we need to drop this object?
                if (OtherGrabbableMustBeHeld != null && !OtherGrabbableMustBeHeld.BeingHeld)
                {
                    ReleaseGrabber();
                    return;
                }

                // Is there a new grab point that's closer?
                if (LiveUpdateNearestGrabPoint)
                {
                    // dummyGrabbable.transform.position =
                    Transform closestGrab = dummyGrabbable.GetClosestGrabPoint(currentGrabber);

                    if (closestGrab != null)
                    {
                        var newPoint = closestGrab.GetComponent <GrabPoint>();
                        if (newPoint != null && newPoint != closestPoint)
                        {
                            UpdateGrabPoint(newPoint);
                        }
                    }
                }

                // Move the hand
                if (MoveInStyle == HandMovement.Lerp)
                {
                    currentGrabber.HandsGraphics.localPosition = Vector3.Lerp(currentGrabber.HandsGraphics.localPosition, currentGrabber.handsGraphicsGrabberOffset, Time.deltaTime * HandSpeed);
                    currentGrabber.HandsGraphics.localRotation = Quaternion.Slerp(currentGrabber.HandsGraphics.localRotation, Quaternion.identity, Time.deltaTime * HandSpeed);
                }

                // User pressed grab key while holding object
                if (currentGrabber.GetInputDownForGrabbable(dummyGrabbable))
                {
                    if (GrabObject != null)
                    {
                        var prevGrabber = currentGrabber;
                        ReleaseGrabber();
                        prevGrabber.GrabGrabbable(GrabObject);
                    }
                }
            }

            // Are we back in the trigger?
            if (grabberInTrigger != null && !grabberInTrigger.HoldingItem && currentGrabber == null)
            {
                setGrabber(grabberInTrigger);
            }
        }
Esempio n. 2
0
        void checkSecondaryLook()
        {
            // Create transform to look at if we are looking at a precise grab
            if (SecondaryGrabbable != null && SecondaryGrabbable.BeingHeld)
            {
                if (SecondaryLookAtTransform == null)
                {
                    Grabber thisGrabber      = GetPrimaryGrabber();
                    Grabber secondaryGrabber = SecondaryGrabbable.GetPrimaryGrabber();

                    GameObject o = new GameObject();
                    SecondaryLookAtTransform      = o.transform;
                    SecondaryLookAtTransform.name = "LookAtTransformTemp";
                    // Precise grab can use current grabber position
                    if (SecondaryGrabbable.GrabMechanic == GrabType.Precise)
                    {
                        SecondaryLookAtTransform.position = secondaryGrabber.transform.position;
                    }
                    // Otherwise use snap point
                    else
                    {
                        Transform grabPoint = SecondaryGrabbable.GetClosestGrabPoint(secondaryGrabber);
                        if (grabPoint)
                        {
                            SecondaryLookAtTransform.position = grabPoint.position;
                        }
                        else
                        {
                            SecondaryLookAtTransform.position = SecondaryGrabbable.transform.position;
                        }

                        SecondaryLookAtTransform.position = SecondaryGrabbable.transform.position;
                    }

                    if (SecondaryLookAtTransform && thisGrabber)
                    {
                        SecondaryLookAtTransform.parent           = thisGrabber.transform;
                        SecondaryLookAtTransform.localEulerAngles = Vector3.zero;
                        SecondaryLookAtTransform.localPosition    = new Vector3(0, 0, SecondaryLookAtTransform.localPosition.z);

                        // Move parent back to grabber
                        SecondaryLookAtTransform.parent = secondaryGrabber.transform;
                    }
                }
            }

            // We should not be aiming at anything if a Grabbable was specified
            if (SecondaryGrabbable != null && !SecondaryGrabbable.BeingHeld && SecondaryLookAtTransform != null)
            {
                clearLookAtTransform();
            }

            Grabber heldBy = GetPrimaryGrabber();

            if (heldBy)
            {
                Transform grabberTransform = heldBy.transform;

                if (SecondaryLookAtTransform != null)
                {
                    // Can use this to offset look
                    //var rotForwardToDown = Quaternion.FromToRotation(Vector3.forward, -Vector3.up);

                    Vector3 initialRotation = grabberTransform.localEulerAngles;

                    Quaternion dest = Quaternion.LookRotation(SecondaryLookAtTransform.position - grabberTransform.position, Vector3.up);
                    grabberTransform.rotation = Quaternion.Slerp(grabberTransform.rotation, dest, Time.deltaTime * SecondHandLookSpeed);

                    // Exclude rotations to only x and y
                    grabberTransform.localEulerAngles = new Vector3(grabberTransform.localEulerAngles.x, grabberTransform.localEulerAngles.y, initialRotation.z);
                }
                else
                {
                    grabberTransform.localEulerAngles = angleLerp(grabberTransform.localEulerAngles, GrabRotationOffset, Time.deltaTime * 20);
                }
            }
        }