コード例 #1
0
    void Update()
    {
        if (Vector3.Distance(leftHandThumbTip.transform.position, leftButtonObj.transform.position) < 0.05f &&
            Vector3.Distance(rightHandThumbTip.transform.position, rightButtonObj.transform.position) < 0.05f)
        {
            // Each finger is near left and right button!

            if (!timeHasStarted)
            {
                time.Start();
                timeHasStarted = true;
            }

            if (time.ElapsedMilliseconds >= 1800)
            {
                // Move the diaphragm!
                float step = 1.0f * Time.deltaTime;
                if (!animationHasFinished)
                {
                    diaphragm.transform.position = Vector3.MoveTowards(diaphragm.transform.position, diaphragmDestination.transform.position, step);
                    if (!audioData.isPlaying)
                    {
                        audioData.Play();
                    }

                    // if the objects are very close, stop the animation!
                    if (Vector3.Distance(diaphragm.transform.position, diaphragmDestination.transform.position) < 0.001f)
                    {
                        // Send a haptic pulse to let the user know that the action is finished
                        vibrate.Vibrate(XRNode.RightHand, 0.5f, 3);
                        vibrate.Vibrate(XRNode.LeftHand, 0.5f, 3);
                        animationHasFinished = true;
                    }
                }
            }
        }
        else
        {
            if (time != null)
            {
                time.Reset();
                timeHasStarted = false;
            }
        }
    }
コード例 #2
0
    void Update()
    {
        handleGrip(HandType.Left);
        handleGrip(HandType.Right);

        // Play animation if it has not already been played
        if (totalRotLeft > 30 && totalRotRight > 30)
        {
            if (!playedAnimation)
            {
                gas.Play();
                steam.Play();
                playedAnimation = true;
                vibrate.Vibrate(XRNode.RightHand, 0.5f, 10);
                vibrate.Vibrate(XRNode.LeftHand, 0.5f, 10);
                IsDone = true;
                if (!audioData.isPlaying)
                {
                    audioData.Play();
                }
            }
        }
    }
コード例 #3
0
    void Update()
    {
        float distLeft  = Vector3.Distance(leftHandAnimation.transform.position, transform.position);
        float distRight = Vector3.Distance(rightHandAnimation.transform.position, transform.position);

        if ((leftHandAnimation.isGrabbing == true && distLeft <= distanceToHand) && !hasBeenRotated ||
            (rightHandAnimation.isGrabbing == true && distRight <= distanceToHand) && !hasBeenRotated)
        {
            performRotation = true;
        }

        if (performRotation == true)
        {
            //print("Rotation: " + objectToRotate.transform.rotation.x);
            if (objectToRotate.transform.rotation.x <= 0.999f)
            {
                hasBeenRotated = true;
                objectToRotate.transform.RotateAround(trans.position, Vector3.left, speed * Time.deltaTime);
            }
        }

        // Get the positions of each thumb to see if the buttons are pressed
        if (hasBeenRotated)
        {
            if (Vector3.Distance(leftHandThumbTip.transform.position, leftButtonObj.transform.position) < 0.05f &&
                Vector3.Distance(rightHandThumbTip.transform.position, rightButtonObj.transform.position) < 0.05f)
            {
                // Each finger is near left and right button!

                if (!timeHasStarted)
                {
                    time.Start();
                    timeHasStarted = true;
                }

                if (time.ElapsedMilliseconds >= 1800)
                {
                    // Move the diaphragm!
                    float step = 1.0f * Time.deltaTime;
                    if (!animationHasFinished)
                    {
                        diaphragm.transform.position = Vector3.MoveTowards(diaphragm.transform.position, diaphragmDestination.transform.position, step);
                        if (!audioData.isPlaying)
                        {
                            audioData.Play();
                        }
                        // if the objects are very close, stop the animation!
                        if (Vector3.Distance(diaphragm.transform.position, diaphragmDestination.transform.position) < 0.001f)
                        {
                            // Send a haptic pulse to let the user know that the action is finished
                            vibrate.Vibrate(XRNode.RightHand, 0.5f, 3);
                            vibrate.Vibrate(XRNode.LeftHand, 0.5f, 3);
                            animationHasFinished = true;
                        }
                    }
                }
            }
            else
            {
                time.Reset();
                timeHasStarted = false;
            }
        }
    }
コード例 #4
0
    void Update()
    {
        if (screwDriver.transform.parent.parent != null)
        {
            whichHand = screwDriver.transform.parent.parent.name;
        }

        float distanceToPivot       = Vector3.Distance(transform.position, screwDriverPivot.transform.position);
        float distanceToDestination = Vector3.Distance(destinationEmpty.transform.position, transform.position);


        //print("Distance is: " + distanceToPivot);

        if (shouldActivate)
        {
            if (shouldCalculateDistance)
            {
                initialDistance         = Vector3.Distance(transform.position, destinationEmpty.transform.position);
                shouldCalculateDistance = false;
            }

            // Check if the pivot point of the screwdriver is in proximity of the screw
            if (distanceToPivot <= interactionDistance)
            {
                float rotatedAmount = screwDriverPivot.transform.eulerAngles.z - previousRotation;
                if ((distanceToDestination > 0.001f && rotatedAmount < -0.5f) || (distanceToDestination > 0.001f && rotatedAmount > 0.5f))
                {
                    Vector3 movement = new Vector3(initialDistance / 180, 0, 0);

                    if (tightenOrLoosen == TightenOrLoosen.Loosen)
                    {
                        rotatedAmount = -rotatedAmount;
                        movement      = -movement;
                    }
                    transform.Rotate(rotatedAmount, 0, 0, Space.Self);
                    totalMovement += Mathf.Abs(movement.magnitude);
                    totalMoved     = Mathf.Abs(totalMovement / (initialDistance - 0.005f));

                    transform.Translate(movement);
                    totalRotated += rotatedAmount;
                }
                else if (distanceToDestination <= 0.005f)
                {
                    doneRotating = true;
                }

                if (doneRotating)
                {
                    if (tightenOrLoosen == TightenOrLoosen.Tighten)
                    {
                        if (whichHand.Equals("RightHand"))
                        {
                            if (!hasSentVibration)
                            {
                                vibrate.Vibrate(XRNode.RightHand, 1, 10);
                                hasSentVibration = true;
                            }
                        }
                        else
                        {
                            if (!hasSentVibration)
                            {
                                vibrate.Vibrate(XRNode.LeftHand, 1, 10);
                                hasSentVibration = true;
                            }
                        }
                    }

                    doneTightening = true;
                    if (tightenOrLoosen == TightenOrLoosen.Tighten)
                    {
                        if (!audioData.isPlaying)
                        {
                            audioData.Play();
                        }
                    }
                }
                previousRotation = screwDriverPivot.transform.eulerAngles.z;
            }
        }
    }