예제 #1
0
    public void returnObject( )
    {
        Debug.Log("Destroy grasp.");

        // Get rigidbody of grasped target
        Rigidbody target = grasp.GetComponent <Rigidbody>();

        // Break grasp
        DestroyImmediate(grasp);

        state = VirtualHandState.Closed;
    }
예제 #2
0
    /*----PICK UP AND RELEASE----*/

    private void PickUp(GameObject item)
    {
        Rigidbody rbItem = item.GetComponent <Rigidbody>();

        if (rbItem != null && !joined)
        {
            heldItem = item;

            // Change the holdPosition's transform to fit the item's size, plus a little bit of padding
            holdPosition.transform.position = transform.parent.position + transform.parent.forward * ((transform.parent.GetComponent <Collider>().bounds.size.z / 2)
                                                                                                      + (heldItem.GetComponent <Collider>().bounds.size.z / 2) + 0.05f);
            heldItem.transform.rotation = holdPosition.rotation;                  // Set itme's rotation to holdPosition's
            heldItem.transform.position = holdPosition.position;                  // Place item in the holdPosition
            heldItem.GetComponent <Collider>().material = heldItemPhysicMaterial; // Set item's physics material to one without friction and bounciness

            // Item ignores collision with player so that there aren't any crazy game-breaking rigidbody bugs like being launched at the speed of light
            Physics.IgnoreCollision(holdPosition.transform.parent.GetComponent <Collider>(), heldItem.GetComponent <Collider>(), true);

            // To actually hold the object and use still use rigidbody physics, the item is held in place (holdPosition) with a FixedJoint.
            // This tells Unity to keep calculating heldItem's rigidbody physics and to not force it through other objects like walls
            // (something that would happen if we set it as a chiled of holdPosition instead)
            heldItem.AddComponent <FixedJoint>();
            FixedJoint fixJoint = heldItem.GetComponent <FixedJoint>();
            fixJoint.GetComponent <FixedJoint>().connectedBody = holdPosition.GetComponent <Rigidbody>();
            joined = true;
        }
    }
예제 #3
0
 private void Update()
 {
     if (currentConnectingObj && Input.GetButtonDown("Fire1"))
     {
         currentConnectingObj.GetComponent <Rigidbody>().AddForce(currentConnectingObj.transform.forward * 30);
         Destroy(currentConnectingObj);
     }
 }
예제 #4
0
    void grabObject(Collider[] GrabColliders)
    {
        FixedJoint joint = GrabColliders[0].transform.parent.gameObject.AddComponent <FixedJoint>() as FixedJoint;

        if (joint.gameObject.tag == "Weapon")
        {
            joint.transform.position = transform.position;
            playerController.swordRB = joint.GetComponent <Rigidbody>();
        }
        joint.connectedBody = rb;
        GrabbedJoint        = joint;
    }
    public Rigidbody Disconnect()
    {
        var viveGrabbable = currentlySelectedObject.GetComponent <ViveGrabbable>();

        if (viveGrabbable != null)
        {
            viveGrabbable.isGrabbed = false;
        }

        isGrabbing = false;
        Rigidbody rigidbody = grabJoint.GetComponent <Rigidbody>();

        Object.Destroy(grabJoint);
        Destroy(jointPoint);
        grabJoint = null;

        currentlySelectedObject.GetComponent <Rigidbody>().useGravity = true;
        currentlySelectedObject = null;

        return(rigidbody);
    }
예제 #6
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }
            //If hand not touching and user pressing button
            else if (button.GetPress())
            {
                hand.type = AffectType.Physical;
                state     = VirtualHandState.Closed;
            }
            // Enlarge
            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }
        // If state is closed
        else if (state == VirtualHandState.Closed)
        {
            // If the user has released the button
            if (!button.GetPress())
            {
                hand.type = AffectType.Virtual;
                state     = VirtualHandState.Open;
            }
        }


        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // If the hand is touching something and the buttonE is pressed
            else if (hand.triggerOngoing && buttonE.GetPress())
            {
                // Change state to holding
                hand.type = AffectType.Virtual;
                state     = VirtualHandState.Enlarge;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }
        // Enlarge
        if (state == VirtualHandState.Enlarge)
        {
            Collider target = hand.ongoingTriggers[0];
            target.transform.localScale += new Vector3(0.1f, 0.1f, 0.1f);
            state = VirtualHandState.Touching;
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
예제 #7
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }
            //If the hand is not touching anything but the trigger button is pressed
            else if (button.GetPress())
            {
                //change the hand interactive to physical
                hand.type = AffectType.Physical;

                //change the state to closed
                state = VirtualHandState.Closed;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                left_target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = left_target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();
                // Change state to holding
                state = VirtualHandState.Holding;
            }
            // Process current touching state
            else
            {
                //Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }
            // Process current holding state
            else
            {
                if (rightHand.triggerOngoing)
                {
                    Collider t = rightHand.ongoingTriggers[0];
                    if (GameObject.ReferenceEquals(left_target.gameObject, t.gameObject))
                    {
                        if (rightButton.GetPress())
                        {
                            state = VirtualHandState.Destroy;
                        }
                    }
                }
            }
        }

        //if the state is destroy
        else if (state == VirtualHandState.Destroy)
        {
            Collider t = rightHand.ongoingTriggers[0];
            DestroyImmediate(grasp);
            Destroy(t.gameObject);
            //Destroy(left_target.gameObject);

            //changing back to open
            state = VirtualHandState.Open;
        }

        else if (state == VirtualHandState.Closed)
        {
            //if the user is not pressing the button
            if (!button.GetPress())
            {
                //update hand interactive to virtual
                hand.type = AffectType.Virtual;

                //Update state to open
                state = VirtualHandState.Open;
            }
            //Process Current closed state
            else
            {
                //Nothing to do for closed
            }
        }
    }
예제 #8
0
 private void OnTriggerStay(Collider collision)
 {
     if (collision.transform.gameObject.tag == "SnapZone" && collision.transform.gameObject.transform.childCount <= 0 && joint != null)
     {
         if (Vector3.Distance(gameObject.transform.position, collision.gameObject.transform.position) <= 0.3f &&
             collision.transform.parent.parent.parent.GetComponent <PlankSpawnController>().type == joint.GetComponent <GroceryDataHandler>().groceryName&&
             !inRange.Contains(collision.gameObject))
         {
             inRange.Add(collision.gameObject);
         }
     }
 }
예제 #9
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        Debug.Log(state);

        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            else if (button.GetPress())
            {
                // Allows the virtual hand to become physical
                hand.type = AffectType.Physical;

                // Change state to closed
                state = VirtualHandState.Closed;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is closed
        else if (state == VirtualHandState.Closed)
        {
            // If the user has released the button
            if (!button.GetPress())
            {
                // Allows the virtual hand to become virtual
                hand.type = AffectType.Virtual;

                // Change state to open
                state = VirtualHandState.Open;
            }

            // Process current closed state
            else
            {
                // Nothing to do for closed
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            else if (hand.triggerOngoing && zoombutton.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to zooming
                state = VirtualHandState.Zooming;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // If state is zooming
        else if (state == VirtualHandState.Zooming)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!zoombutton.GetPress() && grasp != null)
            {
                DestroyImmediate(grasp);
                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current zooming state
            else
            {
                // Get transform of grasped target
                Transform target = grasp.GetComponent <Transform> ();

                // Apply size scaling to target
                target.localScale = svm.scaling;
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }
            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }
            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // If displace button is pressed along with grasp and trigger button
            else if (button1.GetPress() && grasp != null && button.GetPress())
            {
                //update state to delete
                state = VirtualHandState.Displace;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        else if (state == VirtualHandState.Displace)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }


            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp

                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            //If displace button has been released
            else if (button.GetPress() && !button1.GetPress())
            {
                state = VirtualHandState.Holding;
            }


            else
            {
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                DestroyImmediate(grasp);

                if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
                }

                else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
                {
                    hand.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
                }

                grasp = target.gameObject.AddComponent <FixedJoint>();

                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is Open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            else if (button.GetPress())
            {
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }

            // Process current Open state
            else
            {
                // Nothing to do for Open
            }
        }
        else if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }
            else
            {
                //do nothing
            }
        }
        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to Open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }



        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button.GetPress() && button2.GetPress() && grasp != null && joystick.GetAxis().y != 0)
            {
                //grasp.gameObject.GetComponent<Rigidbody>().transform.localScale += new Vector3(25,25,25) ;
                state = VirtualHandState.ScaleUpDown;
            }
            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button.GetPress() && button2.GetPress() && joystick.GetAxis().x != 0)
            {
                state = VirtualHandState.RotationLR;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        else if (state == VirtualHandState.RotationLR)
        {
            if (button2.GetPress() && grasp != null)
            {
                if (joystick.GetAxis().x < 0.2f && joystick.GetAxis().x > 0f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 30f, 0);
                }
                else if (joystick.GetAxis().x < 0.6f && joystick.GetAxis().x >= 0.2f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 60f, 0);
                }
                else if (joystick.GetAxis().x <= 1f && joystick.GetAxis().x >= 0.6f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 90f, 0);
                }

                else if (joystick.GetAxis().x > -0.2f && joystick.GetAxis().x < 0f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -30f, 0);
                }
                else if (joystick.GetAxis().x > -0.6f && joystick.GetAxis().x < -0.2f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -60f, 0);
                }
                else if (joystick.GetAxis().x >= -1f && joystick.GetAxis().x < -0.6f)
                {
                    hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, -90f, 0);
                }
            }

            else if (!button.GetPress() && grasp != null && !button2.GetPress())
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 0f, 0);
                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (!button2.GetPress())
            {
                hand.gameObject.GetComponent <Rigidbody>().transform.eulerAngles = new Vector3(0, 0f, 0);
                state = VirtualHandState.Holding;
            }
            else if (!button2.GetPress() && grasp == null)
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Closed;
            }
            else
            {
            }
        }

        else if (state == VirtualHandState.ScaleUpDown)
        {
            if (grasp == null)
            {
                // Update state to Open
                state = VirtualHandState.Open;
            }


            else if (button2.GetPress() && grasp != null && button.GetPress())
            {
                if (joystick.GetAxis().y < 0f)
                {
                    grasp.gameObject.GetComponent <Rigidbody>().transform.localScale -= new Vector3(0.0001f, 0.0001f, 0.0001f);
                }
                else if (joystick.GetAxis().y > 0f)
                {
                    grasp.gameObject.GetComponent <Rigidbody>().transform.localScale += new Vector3(0.0001f, 0.0001f, 0.0001f);
                }
            }


            else if (!button.GetPress() && grasp != null && !button2.GetPress())
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);

                DestroyImmediate(grasp);
                // Apply physics to target in the event of attempting to throw it

                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;
                // Update state to Open
                state = VirtualHandState.Open;
            }

            else if (!button2.GetPress())
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Holding;
            }

            else if (!button2.GetPress() && grasp == null)
            {
                //grasp.GetComponent<Rigidbody>().transform.localScale -= new Vector3(25,25,25);
                state = VirtualHandState.Closed;
            }


            else
            {
                // Nothing to do for holding
            }
        }
        //else if(state ==)
    }
예제 #12
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                Debug.Log("Touching");
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }
            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }

            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            else if (hand.triggerOngoing && grip.GetPressDown())
            {
                Debug.Log("Apply");
                Collider target = hand.ongoingTriggers[0];

                if (target.GetComponent <Status>())
                {
                    status = target.GetComponent <Status>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <Status>().isOn = status;
                    }
                    else if (status == false)
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <Status>().isOn = status;
                    }
                }
                else if (target.GetComponent <GoggleScript>())
                {
                    status = target.GetComponent <GoggleScript>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <GoggleScript>().isOn = status;
                    }
                    else if (status == false)
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <GoggleScript>().isOn = status;
                    }
                }

                state = VirtualHandState.Apply;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }


            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        else if (state == VirtualHandState.Apply)
        {
            if (grasp == null && !grip.GetPressDown() && !hand.triggerOngoing)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }
            else if (grasp == null && !grip.GetPressDown() && hand.triggerOngoing)
            {
                state = VirtualHandState.Touching;
            }


            else
            {
            }
        }
    }
예제 #13
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (solarSystem.transform.localScale.x >= .0021f)
        {
            foreach (GameObject p in planets)
            {
                p.GetComponent <Planet>().DisableMotionControl();
            }
        }
        else
        {
            foreach (GameObject p in planets)
            {
                p.GetComponent <Planet>().EnableMotionControl();
            }
        }

        // If state is open
        if (state == VirtualHandState.Open)
        {
            Debug.Log("Hand is open");
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                if (exitButton.GetPress())
                {
                    solarSystem.transform.localScale = new Vector3(0.002f, 0.002f, .002f);
                    solarSystem.transform.position   = new Vector3(0, 1.2f, 0.5f);
                }
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            Debug.Log("Hand is touching");
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                Collider t = hand.ongoingTriggers[0];
                planet = t.gameObject;
                Vector3 planetLocation = planet.transform.position;
                Vector3 locationDiff;
                if (touchPadButton.GetPress())
                {
                    Vector3 curScale = solarSystem.transform.localScale;
                    if (joystick.GetAxis().y > 0 && curScale.x < .03f)
                    {
                        solarSystem.transform.localScale = new Vector3(curScale.x, curScale.y, curScale.z) + new Vector3(scaleRate, scaleRate, scaleRate);
                        locationDiff = planetLocation - planet.transform.position;
                        solarSystem.transform.Translate(locationDiff);
                        Debug.Log(solarSystem.transform.localScale.x * 1.0f);
                    }
                    else if (joystick.GetAxis().y < 0 && curScale.x > .0021f)
                    {
                        solarSystem.transform.localScale = new Vector3(curScale.x, curScale.y, curScale.z) - new Vector3(scaleRate, scaleRate, scaleRate);
                        locationDiff = planetLocation - planet.transform.position;
                        solarSystem.transform.Translate(locationDiff);
                        Debug.Log(solarSystem.transform.localScale.x * 1.0f);
                    }
                }
                if (exitButton.GetPress())
                {
                    solarSystem.transform.localScale = new Vector3(0.002f, 0.002f, .002f);
                    solarSystem.transform.position   = new Vector3(0, 1.2f, 0.5f);
                }
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            Debug.Log("Hand is holding");
            Collider t = hand.ongoingTriggers[0];
            planet = t.gameObject;
            GameObject zc = GameObject.Find("ZoomControl");
            zc.GetComponent <ZoomControl>().ZoomToPlanet(planet);
            state = VirtualHandState.Zoomed;
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                //state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                //state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
        else if (state == VirtualHandState.Zoomed)
        {
            GameObject ac = GameObject.Find("AudioController");
            previousPageNumber = pageNumber;
            touchButtonPress   = touchPadButton.GetPress();
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }
            //Navigate right page
            if (pageNumber < 3 && joystick.GetAxis().x > 0.0f && !touchButtonPress && prevTouchButtonPress)
            {
                pageNumber++;
            }
            //Navigate left page
            else if (pageNumber > 1 && joystick.GetAxis().x < 0.0f && !touchButtonPress && prevTouchButtonPress)
            {
                pageNumber--;
            }

            if (pageNumber != previousPageNumber)
            {
                Debug.Log("Setting audio");
                //Set audio
                ac.GetComponent <AudioController>().SetAudio(pageNumber, planet);
                //Set text on panel
            }

            //UI control starts

            GameObject PlanetUI = planet.transform.Find(planet.name + "Info").gameObject;

            //Rotate panel to face user
            if (previousPageNumber == 0)
            {
                GameObject hmd   = GameObject.Find("Vive HMD");
                float      angle = getPanelRotation(hmd.transform.position.x, hmd.transform.position.z);
                PlanetUI.transform.rotation = Quaternion.Euler(0, angle, 0);
            }

            PlanetUI.gameObject.SetActive(true);
            for (int i = 1; i < 4; i++)
            {
                if (i == pageNumber)
                {
                    PlanetUI.transform.GetChild(i - 1).gameObject.SetActive(true);
                }
                else
                {
                    PlanetUI.transform.GetChild(i - 1).gameObject.SetActive(false);
                }
            }

            //UI contro ends

            if (exitButton.GetPress())
            {
                PlanetUI.gameObject.SetActive(false);

                GameObject zc = GameObject.Find("ZoomControl");
                zc.GetComponent <ZoomControl>().ZoomOut();
                pageNumber = 0;
                state      = VirtualHandState.Open;
                ac.GetComponent <AudioController>().StopAudio();
            }


            prevTouchButtonPress = touchButtonPress;
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the btnTouchpad is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If btnTouchpad has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }
예제 #15
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                Debug.Log("Touching");
                state = VirtualHandState.Touching;
            }

            // If the hand is closed
            else if (button.GetPress() && !menu.GetPressDown())
            {
                // Change state to closed
                state     = VirtualHandState.Closed;
                hand.type = AffectType.Physical;
            }

            else if (menu.GetPressDown())
            {
                if (button.GetPressDown())
                {
                    Debug.Log("HandleTriggerClicked");
                    if (EventSystem.current.currentSelectedGameObject != null)
                    {
                        ExecuteEvents.Execute(EventSystem.current.currentSelectedGameObject, new PointerEventData(EventSystem.current), ExecuteEvents.submitHandler);
                        return;
                    }
                }

                GameObject menuUIObj;
                GameObject menuBeamObj;
                menuUIObj = GameObject.Find("MainMenuObjectHelper");

                menustatus = menuUIObj.GetComponent <MenuUI>().isOn;
                //menustatus = menuUIObj.activeInHierarchy;

                menuBeamObj    = GameObject.Find("MenuBeamHelper");
                menuBeamStatus = menuBeamObj.GetComponent <MenuBeam>().isOn;

                if (menustatus == true)
                {
                    Debug.Log("TurnOff");
                    menustatus = false;
                    menuUIObj.GetComponent <MenuUI>().isOn     = menustatus;
                    menuBeamObj.GetComponent <MenuBeam>().isOn = menustatus;
                }
                else if (menustatus == false)
                {
                    Debug.Log("TurnOn");
                    menustatus = true;
                    menuUIObj.GetComponent <MenuUI>().isOn     = menustatus;
                    menuBeamObj.GetComponent <MenuBeam>().isOn = menustatus;
                }

                // Change state to Select
                state = VirtualHandState.Select;
            }

            else
            {
                // do nothing
            }
        }

        //If state is closed
        if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                //change state to open
                state     = VirtualHandState.Open;
                hand.type = AffectType.Virtual;
            }

            else
            {
                //do nothing
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                Collider target = hand.ongoingTriggers[0];

                if (target.GetComponent <Status>())
                {
                    status = target.GetComponent <Status>().isOn;
                    if (status == true)
                    {
                        Debug.Log("TurnOff");
                        status = false;
                        target.GetComponent <Status>().isOn = status;
                    }
                    else
                    {
                        Debug.Log("TurnOn");
                        status = true;
                        target.GetComponent <Status>().isOn = status;
                    }
                }

                if (target.GetComponent <Vision>())
                {
                    status = target.GetComponent <Vision>().isOn;
                    if (status == true)
                    {
                        status = false;
                        target.GetComponent <Vision>().isOn = status;
                        //grasp = target.GetComponent<Vision>().goggle.gameObject.AddComponent<FixedJoint>();
                        //grasp.connectedBody = hand.gameObject.GetComponent<Rigidbody>();
                    }
                }


                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint>();
                // Set the connection
                grasp.connectedBody = hand.gameObject.GetComponent <Rigidbody>();

                if (target.gameObject.tag == "goggle")
                {
                    hand.gameObject.tag = "goggle";
                }


                // Change state to holding
                state = VirtualHandState.Holding;
            }

            //else if (hand.triggerOngoing && grip.GetPressDown())
            //{
            //    Debug.Log("Apply");
            //    Collider target = hand.ongoingTriggers[0];

            //    if (target.GetComponent<Status>())
            //    {
            //        status = target.GetComponent<Status>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Status>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Status>().isOn = status;
            //        }
            //    }

            //    if (target.GetComponent<Goggles>())
            //    {
            //        status = target.GetComponent<Goggles>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Goggles>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Goggles>().isOn = status;
            //        }
            //    }

            //    if (target.GetComponent<Vision>())
            //    {
            //        status = target.GetComponent<Vision>().isOn;
            //        if (status == true)
            //        {
            //            Debug.Log("TurnOff");
            //            status = false;
            //            target.GetComponent<Vision>().isOn = status;

            //        }
            //        else if (status == false)
            //        {
            //            Debug.Log("TurnOn");
            //            status = true;
            //            target.GetComponent<Vision>().isOn = status;
            //        }
            //    }

            //    state = VirtualHandState.Apply;

            //}

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!button.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody>();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = hand.velocity * speed;
                target.angularVelocity = hand.angularVelocity * speed;

                hand.gameObject.tag = "hands";

                // Update state to open
                state = VirtualHandState.Open;
            }


            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }

        // if state is displacing
        //else if (state == VirtualHandState.Apply)
        //{

        //    if (grasp == null && !grip.GetPressDown() && !hand.triggerOngoing)
        //    {
        //        // Update state to open
        //        state = VirtualHandState.Open;
        //    }
        //    else if (grasp == null && !grip.GetPressDown() && hand.triggerOngoing)
        //    {
        //        state = VirtualHandState.Touching;
        //    }

        //    else
        //    {

        //    }

        //}

        else if (state == VirtualHandState.Select)
        {
            if (!menu.GetPressDown())
            {
                state = VirtualHandState.Open;
            }
        }
    }
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (leftGrip.GetPress() && rightGrip.GetPress())
        {
            // Reset the game
            drone_transform.position = initial_drone_position + reset_position_offset;
            drone_transform.rotation = initial_drone_rotation;
            drone_transform.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
        }

        // If state is open
        if (state == VirtualHandState.Open)
        {
            // If the hand is touching something
            if (rightHand.triggerOngoing)
            {
                // Change state to touching
                state = VirtualHandState.Touching;
            }

            // Process current open state
            else
            {
                // Nothing to do for open
            }
        }

        // If state is touching
        else if (state == VirtualHandState.Touching)
        {
            // If the hand is not touching something
            if (!rightHand.triggerOngoing)
            {
                // Change state to open
                state = VirtualHandState.Open;
            }

            // If the hand is touching something and the button is pressed
            else if (rightHand.triggerOngoing && rightTrigger.GetPress() && leftTrigger.GetPress())
            {
                // Fetch touched target
                Collider target = rightHand.ongoingTriggers [0];
                // Create a fixed joint between the hand and the target
                grasp = target.gameObject.AddComponent <FixedJoint> ();
                // Set the connection
                grasp.connectedBody = rightHand.gameObject.GetComponent <Rigidbody> ();

                // Change state to holding
                state = VirtualHandState.Holding;
            }

            // Process current touching state
            else
            {
                // Nothing to do for touching
            }
        }

        // If state is holding
        else if (state == VirtualHandState.Holding)
        {
            // If grasp has been broken
            if (grasp == null)
            {
                // Update state to open
                state = VirtualHandState.Open;
            }

            // If button has been released and grasp still exists
            else if (!rightTrigger.GetPress() && !leftTrigger.GetPress() && grasp != null)
            {
                // Get rigidbody of grasped target
                Rigidbody target = grasp.GetComponent <Rigidbody> ();
                // Break grasp
                DestroyImmediate(grasp);

                // Apply physics to target in the event of attempting to throw it
                target.velocity        = rightHand.velocity * speed;
                target.angularVelocity = rightHand.angularVelocity * speed;

                // Update state to open
                state = VirtualHandState.Open;
            }

            // Process current holding state
            else
            {
                // Nothing to do for holding
            }
        }
    }