コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (currentState == gameState.tutorial)
        {
            hideCourses(true);
            obstacles.SetActive(false);

            if (!tutorialManager.isAudioPlaying() && tutorialManager.getCurrentEvent() < 14)
            {
                if (playFirst)
                {
                    tutorialManager.GoToEvent(0);
                    playFirst = false;
                }
                else
                {
                    tutorialManager.PlayNextEvent();
                }
            }

            if (leftGrip.GetPress() && rightGrip.GetPress())
            {
                currentState = gameState.course;
                print(currentState.ToString());
            }
        }

        else if (currentState == gameState.course)
        {
            hideCourses(false);
            obstacles.SetActive(false);

            if (leftGrip.GetPress() && rightGrip.GetPress())
            {
                currentState = gameState.freeroam;
                print(currentState.ToString());
            }
        }
        else
        {
            hideCourses(true);
            obstacles.SetActive(true);

            if (leftGrip.GetPress() && rightGrip.GetPress())
            {
                currentState = gameState.tutorial;
                print(currentState.ToString());
            }
        }
    }
コード例 #2
0
        void FixedUpdate()
        {
            Vector2 raw_left         = left_joystick.GetAxis();
            Vector2 raw_right        = right_joystick.GetAxis();
            Vector2 input_left       = raw_left * max_translation_deflection;
            Vector2 input_right      = raw_right * max_translation_deflection;
            Vector3 left_deflection  = new Vector3(input_left.x, 0f, input_left.y);
            Vector3 right_deflection = new Vector3(input_right.x, 0f, input_right.y);

            if (left_trigger.GetPress() && right_trigger.GetPress())
            {
                drone.transform.position = drone_start_position;
                drone.transform.rotation = drone_start_rotation;
                drone.GetComponent <Rigidbody>().velocity        = Vector3.zero;
                drone.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
            }
            if (left_button.GetPress())
            {
                left_cursor.localPosition = left_joy_start_pos - left_deflection;
            }
            else
            {
                left_cursor.localPosition = left_joy_start_pos;
            }
            if (right_button.GetPress())
            {
                right_cursor.localPosition = right_joy_start_pos - right_deflection;
            }
            else
            {
                right_cursor.localPosition = right_joy_start_pos;
            }
        }
コード例 #3
0
ファイル: MenuHand.cs プロジェクト: ArshartCloud/FitnessGames
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void Update()
    {
        /*
         * Ray ray = new Ray(hand.position, Vector3.forward);
         * RaycastHit hit;
         * Debug.Log(hand.position);
         * Debug.Log(hand.position + Vector3.forward * maxRayDistance);
         * Debug.DrawLine(hand.position, hand.position + Vector3.forward * maxRayDistance, Color.red, Time.deltaTime, false);
         *
         * if (Physics.Raycast(ray, out hit, maxRayDistance))
         * {
         *  Debug.Log("you hit");
         * }
         * // If state is open*/
        if (state == MenuHandState.Open)
        {
            // If the hand is touching something
            if (hand.triggerOngoing)
            {
                // Change state to touching
                state = MenuHandState.Touching;
            }
        }

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

            // If the hand is touching something and the button is pressed
            else if (hand.triggerOngoing && button.GetPress())
            {
                // Fetch touched target
                GameObject go = hand.ongoingTriggers[0].gameObject;
                if (go.tag == "Button")
                {
                    go.GetComponent <MeshRenderer>().material = changeMaterial;
                    if (go.name == "Exit")
                    {
                        EditorApplication.isPlaying = false;
                    }
                    else
                    {
                        //go.GetComponent<Material>().mainTexture = texture;
                        GameManager.gameMode = (GameMode)System.Enum.Parse(typeof(GameMode), go.name);
                        //SceneManager.LoadScene(go.name, LoadSceneMode.Single);
                        SceneManager.LoadScene("Mixed", LoadSceneMode.Single);
                    }
                }
            }
        }
    }
コード例 #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 raw_left  = left_joystick.GetAxis();
        Vector2 raw_right = right_joystick.GetAxis();
        //Debug.Log("Raw Left: " + raw_left);
        //Debug.Log("Raw Right: " + raw_right);
        Vector2 left_input  = raw_left * max_translation_deflection;
        Vector2 right_input = raw_right * max_translation_deflection;
        Vector3 left_3      = new Vector3(left_input.x, 0f, left_input.y);
        Vector3 right_3     = new Vector3(right_input.x, 0f, right_input.y);

        left_cursor.localPosition  = left_joy_start_position - left_3;
        right_cursor.localPosition = right_joy_start_position - right_3;
        if (left_trigger.GetPress() && right_trigger.GetPress())
        {
            drone.transform.position = initial_drone_position;
            drone.transform.rotation = initial_drone_rotation;
            drone.gameObject.GetComponent <Rigidbody>().velocity        = Vector3.zero;
            drone.gameObject.GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
        }
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        buttonPress = button.GetPress();
        if (!buttonPress && prevButtonPress)
        {
            foreach (GameObject p in planets)
            {
                p.GetComponent <Planet>().ToggleMotion();
            }
        }

        //Vector3 scalingRateV3 = new Vector3(scalingRate, scalingRate, scalingRate);
        //Vector3 finalScale = curScale + scaleJoystrick.GetAxis().y * scalingRateV3;
        //if (finalScale.x <= 0 || finalScale.y <= 0 || finalScale.z <= 0)
        //{
        //    finalScale = new Vector3(0.002F, 0.002F, 0.002F);
        //}
        //Debug.Log("y is " + scaleJoystrick.GetAxis().y);
        //Debug.Log("curScale is " + curScale * 1000);
        //Debug.Log("finalScale is " + finalScale * 1000);
        //solarSystem.transform.localScale = finalScale;

        prevButtonPress = buttonPress;
    }
コード例 #6
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;
            }
        }
    }
コード例 #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 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;
            }
        }
    }
コード例 #8
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;
            }

            // 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
                Collider target = hand.ongoingTriggers[0];

                // If a particle is to be removed from the structure
                if (target.gameObject.name.Contains("Electron") || target.gameObject.name.Contains("Proton") || target.gameObject.name.Contains("Neutron"))
                {
                    GameObject.Find("RemoveParticles").GetComponent <RemoveParticles>().interaction(target.gameObject);
                    state = VirtualHandState.Closed;
                }

                /*
                 *  else if (target.gameObject.name.Contains("CircularProgressBar")) {
                 *  Debug.Log("sgdyugd");
                 *  state = VirtualHandState.Closed;
                 *  }
                 */

                // If the button is pressed for the quiz to begin
                else if (target.gameObject.name.Contains("Start Quiz Button"))
                {
                    GameObject.Find("ClickSound").GetComponent <ClickSound>().playClick();
                    GameObject.Find("QuizScript").GetComponent <Quiz>().startQuiz();
                    state = VirtualHandState.Closed;
                }

                // If the submit button is pressed to answer a question
                else if (target.gameObject.name.Contains("Submit Answer Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().submitAnswer();
                    state = VirtualHandState.Closed;
                }

                // If the see solution button is pressed
                else if (target.gameObject.name.Contains("See Solution Button"))
                {
                    GameObject.Find("ClickSound").GetComponent <ClickSound>().playClick();
                    GameObject.Find("QuizScript").GetComponent <Quiz>().showSolution();
                    state = VirtualHandState.Closed;
                }

                // If answer choice 1 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 1 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(1);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 2 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 2 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(2);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 3 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 3 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(3);
                    state = VirtualHandState.Closed;
                }

                // If answer choice 4 button is pressed
                else if (target.gameObject.name.Contains("Answer Choice 4 Button"))
                {
                    GameObject.Find("QuizScript").GetComponent <Quiz>().answerChoicePressed(4);
                    state = VirtualHandState.Closed;
                }

                // Checks if the user has selected one of the selectable elements on the Periodic Table.
                // It then adjusts the Highlighting value and model's value accordingly.
                // It will NOT create a joint and will keep the element stationary (except highlighting feature which is called).

                // Check for Hydrogen
                else if (target.gameObject == hydrogen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 1)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Hydrogen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(1);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Hellium
                else if (target.gameObject == hellium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 2)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Hellium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(2);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Lithium
                else if (target.gameObject == lithium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 3)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Lithium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(3);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Beryllium
                else if (target.gameObject == beryllium)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 4)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Beryllium
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(4);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Boron
                else if (target.gameObject == boron)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 5)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Boron
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(5);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Carbon
                else if (target.gameObject == carbon)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 6)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Carbon
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(6);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Nitrogen
                else if (target.gameObject == nitrogen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 7)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Nitrogen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(7);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Oxygen
                else if (target.gameObject == oxygen)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 8)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Oxygen
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(8);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Flourine
                else if (target.gameObject == fluorine)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 9)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Flourine
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(9);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // Check for Neon
                else if (target.gameObject == neon)
                {
                    // Dismiss element from table if it is already selected
                    if (GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().element == 10)
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(0);
                    }

                    // If element is not already selected, set it to Neon
                    else
                    {
                        GameObject.Find("AtomicStructure").GetComponent <AtomicStructureBaseClass>().changeElement(10);
                    }

                    // Changes state to closed so the user will have to release the trigger before selecting anything else
                    state = VirtualHandState.Closed;
                }

                // If user has selected an interactable object NOT on the Periodic Table.
                else
                {
                    // 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 closed
        else if (state == VirtualHandState.Closed)
        {
            if (!button.GetPress())
            {
                state = VirtualHandState.Open;
            }
            else
            {
                //do nothing
            }
        }

        // 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 (returnObjectHome == true)
             * {
             *  Debug.Log("Destroy grasp.");
             *
             *  // Get rigidbody of grasped target
             *  Rigidbody target = grasp.GetComponent<Rigidbody>();
             *  // Break grasp
             *  DestroyImmediate(grasp);
             *
             *  returnObjectHome = false;
             *  state = VirtualHandState.Closed;
             * }
             */

            // 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
            }
        }
    }
コード例 #9
0
    void updateHand(VirtualHandInfo hi)
    {
        VirtualHandState state  = hi.state;
        Affect           hand   = hi.hand;
        CommonButton     button = hi.button;
        GameObject       target = hi.target;

        if (state == VirtualHandState.Open)
        {
            if (hand.triggerOngoing)
            {
                state = VirtualHandState.Touching;
            }
            else
            {
            }
        }
        else if (hi.state == VirtualHandState.Touching)
        {
            if (!hand.triggerOngoing)
            {
                // Change state to open
                state  = VirtualHandState.Open;
                target = null;
            }
            else
            {
                if (button.GetPress() && target == null && !hand.ongoingTriggers [0].GetComponent <Interactive>().isHeavy)
                {
                    target = hand.ongoingTriggers [0].gameObject;

                    JackHook jackHook = target.GetComponent <JackHook> ();
                    if (jackHook == null)
                    {
                        SnapTarget snap = target.GetComponent <SnapTarget> ();

                        if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                        {
                            state  = VirtualHandState.Open;
                            target = null;
                        }
                        else
                        {
                            if (snap != null)
                            {
                                snap.setState(FAFVR.SnapTargetState.Holding);
                            }

                            TireIron ti = target.GetComponent <TireIron> ();
                            if (ti != null)
                            {
                                ti.SetStatus(TireIronStatus.OneHandHolding);
                            }
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                        }
                    }
                    else
                    {
                        if (jackHook.state == JackHookState.Open)
                        {
                            Rigidbody rig = target.GetComponent <Rigidbody> ();
                            rig.isKinematic         = true;
                            rig.useGravity          = false;
                            target.transform.parent = hand.gameObject.transform;
                            state = VirtualHandState.Holding;
                            jackHook.SetState(JackHookState.Holding);
                            jackHook.isRotating = false;
                        }
                        else if (jackHook.state == JackHookState.Connecting)
                        {
                            jackHook.isRotating = true;
                        }
                        else
                        {
                            jackHook.isRotating = false;
                        }
                    }
                }
            }
        }
        else if (hi.state == VirtualHandState.Holding)
        {
            if (target == null)
            {
                state = VirtualHandState.Open;
            }
            else
            {
                SnapTarget snap = target.GetComponent <SnapTarget> ();
                if (snap != null && snap.state == FAFVR.SnapTargetState.Locked)
                {
                    target.transform.parent = world;
                    target = null;
                    state  = VirtualHandState.Open;
                }
                else if (!button.GetPress() && target != null)
                {
                    Rigidbody rig = target.GetComponent <Rigidbody> ();
                    rig.isKinematic         = false;
                    rig.useGravity          = true;
                    target.transform.parent = world;

                    state = VirtualHandState.Open;

                    snap = target.GetComponent <SnapTarget> ();

                    if (snap != null)
                    {
                        snap.setState(FAFVR.SnapTargetState.Open);
                    }

                    if (target.GetComponent <JackHook> () != null)
                    {
                        target.GetComponent <JackHook> ().state = JackHookState.Open;
                    }
                    target = null;
                }
            }
        }

        hi.state  = state;
        hi.target = target;
    }
コード例 #10
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            ResetHeight();
            // If the joystick is pressed forward and the btnTouchpad is pressed
            if (joystick.GetAxis().y > 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y < 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }
            else if (btnTrigger.GetPress())
            {
                state = SteeringState.Hop;
            }

            else if (btnTeleport.GetPress())
            {
                state = SteeringState.Teleport;
            }
            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the btnTouchpad is not pressed
            if (!btnTouchpad.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y < 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                // Added to avoid flying up or down while moving
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the btnTouchpad is not pressed
            if (!btnTouchpad.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the btnTouchpad is pressed
            else if (joystick.GetAxis().y > 0.0f && btnTouchpad.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                // Added to avoid flying up or down while moving
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // if state is hop
        else if (state == SteeringState.Hop)
        {
            // If the btnTrigger is not pressed
            if (!btnTrigger.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Hop();
            }
        }

        // if state is teleport
        else if (state == SteeringState.Teleport)
        {
            // If the btnTeleport is not pressed
            if (!btnTeleport.GetPress())
            {
                // Return state to NotSteering
                state = SteeringState.NotSteering;
                // Set teleportFlag to true, to let the user teleport again.
                teleportFlag = true;
            }
            else
            {
                // ensures that the user can teleport only one level when they press the trigger
                if (teleportFlag)
                {
                    // move to another room
                    Teleport();
                }
            }
        }
    }
コード例 #11
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.WalkingForward;
            }

            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running Backward
                state = SteeringState.RunningBackward;
            }


            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.WalkingForward)
        {
            //if speen is increased, The user will go into running state from walking state.
            if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // If the button is not pressed
            else if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.WalkingBackward;
            }

            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningBackward;
            }


            // Process current steering forward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.WalkingBackward)
        {
            if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                //changing the state to Running backward
                state = SteeringState.RunningBackward;
            }

            // If the button is not pressed
            else if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.WalkingForward;
            }

            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                //changing the state to Running Forward
                state = SteeringState.RunningForward;
            }

            // Process current steering backward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
        else if (state == SteeringState.RunningForward)
        {
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                state = SteeringState.WalkingForward;
            }
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y <= -0.5f && button.GetPress())
            {
                state = SteeringState.RunningBackward;
            }
            else if (!button.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
        else if (state == SteeringState.RunningBackward)
        {
            if (joystick.GetAxis().y > 0.0f && joystick.GetAxis().y < 0.5f && button.GetPress())
            {
                state = SteeringState.WalkingForward;
            }
            else if (joystick.GetAxis().y < 0.0f && joystick.GetAxis().y > -0.5f && button.GetPress())
            {
                state = SteeringState.WalkingBackward;
            }
            else if (joystick.GetAxis().y >= 0.5f && button.GetPress())
            {
                state = SteeringState.RunningForward;
            }
            else if (!button.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
    }
コード例 #12
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }


            // If the trigger button is pressed
            else if (jumpButton.GetPress())
            {
                // Change state to jump state
                state = SteeringState.Jump;
            }



            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }


        // If it is a jump state
        else if (state == SteeringState.Jump)
        {
            // If the button is not pressed
            if (!jumpButton.GetPress())
            {
                // Change state to fall
                state = SteeringState.Fall;
            }


            // Process current steering jump state
            else
            {
                Vector3 direction;
                direction = Vector3.up;

                // Translate the space to so that the user can jump
                while (i < 10)
                {
                    space.transform.position += Vector3.up * Time.deltaTime;
                    if (i == 9)
                    {
                        Thread.Sleep(1000);
                    }

                    i++;
                }
            }
        }
    }
コード例 #13
0
ファイル: Steering.cs プロジェクト: saayv1/Driving-Hazards
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        if (isHit)
        {
            state = SteeringState.ForcedBrake;
        }
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            if (trigger.GetPress() || joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }

            if (joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }
            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        else if (state == SteeringState.Accelerate)
        {
            played = false;
            if (BrakeTrigger.GetPress())
            {
                state = SteeringState.Brake;
            }
            else if (!trigger.GetPress() && joystick.GetAxis().x == 0)
            {
                state = SteeringState.Decelerate;
            }

            else
            {
                deltaRotation             = GameObject.Find("scripts/VirtualHand").GetComponent <VirtualHand> ().deltaRotation;
                speed                     = joystick.GetAxis().x *acceleration_factor *   100;
                space.transform.position += space.transform.forward * Time.deltaTime * speed;
                space.transform.Rotate(0, deltaRotation.y * 20, 0);
                Debug.Log("Accelerate");
                if (acc_sound.isPlaying)
                {
                }
                else
                {
                    acc_sound.Play();
                    brk_sound.Stop();
                }
            }
        }
        else if (state == SteeringState.Decelerate)
        {
            if (BrakeTrigger.GetPress())
            {
                state = SteeringState.NotSteering;
            }
            else if (speed <= 0)
            {
                state = SteeringState.NotSteering;
            }
            else if (trigger.GetPress() || joystick.GetAxis().x > 0)
            {
                state = SteeringState.Accelerate;
            }
            else
            {
                deltaRotation             = GameObject.Find("scripts/VirtualHand").GetComponent <VirtualHand> ().deltaRotation;
                space.transform.position += space.transform.forward * speed * Time.deltaTime;
                speed -= speed * acceleration_factor;
                space.transform.Rotate(0, deltaRotation.y * 20, 0);
                Debug.Log("Decelerate");
                acc_sound.Stop();
            }
        }

        else if (state == SteeringState.Brake)
        {
            if (!BrakeTrigger.GetPress())
            {
                state = SteeringState.Decelerate;
            }
            else if (speed <= 0)
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                //space.transform.position += space.transform.forward * speed * Time.deltaTime * acceleration_factor;
                space.transform.position += space.transform.forward * speed * Time.deltaTime;
                speed -= speed * acceleration_factor;
                Debug.Log("Brake");
                if (brk_sound.isPlaying || played)
                {
                }
                else
                {
                    brk_sound.Play();
                    acc_sound.Stop();
                    played = true;
                }
            }
        }
        else if (state == SteeringState.ForcedBrake)
        {
            acc_sound.Stop();
            brk_sound.Stop();
            Debug.Log("force brake");
            if (gripButton.GetPress())
            {
                space.transform.rotation = originalSpaceRotation;
                space.transform.position = originalSpaceTransform;
                car.transform.rotation   = originalCarRotation;
                car.transform.position   = originalCarTransform;
                GameObject broken_window = GameObject.Find("front_window_broken");
                GameObject good_window   = GameObject.Find("front_window");

                GameObject steeringWheel = GameObject.Find("steeringpivot");
                steeringWheel.transform.rotation = originalWheelRotation;
                steeringWheel.transform.position = originalWheelTransform;
                speed = 0;

                deltaRotation.Set(0, 0, 0, 0);

                broken_window.GetComponent <MeshRenderer>().enabled = false;
                good_window.GetComponent <MeshRenderer>().enabled   = true;
                isHit = false;
                state = SteeringState.NotSteering;
            }
            else if (speed <= 1)
            {
                state = SteeringState.NotSteering;
            }
            else
            {
                space.transform.position += space.transform.forward * speed * Time.deltaTime * -1 * acceleration_factor;
                speed -= speed * acceleration_factor;
            }
        }
    }
コード例 #14
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }



            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // Process current steering forward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *tracker.transform.forward *speed *Time.deltaTime;
            }
        }

        //HW2 - if state is steering leftward
        else if (state == SteeringState.SteeringLeft)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed rightward and the button is pressed
            else if (joystick.GetAxis().x > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                //HW2 - Change state to steering rightward
                state = SteeringState.SteeringRight;
            }

            // Process current strafe left state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
            }
        }

        //HW2 - If state is steering rightward
        else if (state == SteeringState.SteeringRight)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) > Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            //HW2 - If the joystick is pressed leftward and the button is pressed
            else if (joystick.GetAxis().x < 0.0f && button.GetPress() && (Mathf.Abs(joystick.GetAxis().y) < Mathf.Abs(joystick.GetAxis().x)))
            {
                // Change state to steering leftward
                state = SteeringState.SteeringLeft;
            }

            // Process current strafe right state
            else
            {
                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *tracker.transform.right *speed *Time.deltaTime;
            }
        }
    }
コード例 #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())
            {
                // 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
            {
            }
        }
    }
コード例 #16
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            // If the joystick is pressed forward and the button is pressed
            if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current not steering state
            else
            {
                // Nothing to do for not steering
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed backward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering backward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering forward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        // If state is steering backward
        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;
                // Translate the space based on the tracker's absolute forward direction and the joystick's forward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }
    }
コード例 #17
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;
        }
    }
コード例 #18
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;
            }

            // 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
            }
        }
    }
コード例 #19
0
    // 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
            }
        }
    }
コード例 #20
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;
            }

            // 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
                initialVector = hand.gameObject.transform.position - steeringWheel.transform.position;

                initialVector = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);

                origSteeringWheelRotation = steeringWheel.transform.rotation;

                // Change state to LeftTurn
                state = VirtualHandState.Grabbing;
            }

            // Process current touching state
            else
            {
                //initialPosition = hand.gameObject.transform.position;



                // Nothing to do for touching
            }
        }

        // If state is LeftTurn
        else if (state == VirtualHandState.Grabbing)
        {
            // If button has been released and grasp still exists
            if (!button.GetPress())
            {
                state = VirtualHandState.Open;
            }

            // Process current LeftTurn state
            else
            {
                currentVector = hand.gameObject.transform.position - steeringWheel.transform.position;
                currentVector = Vector3.ProjectOnPlane(currentVector, steeringWheelNormal);

                Quaternion deltaRotation = new Quaternion();
                deltaRotation.SetFromToRotation(initialVector, currentVector);
                steeringWheel.transform.rotation = deltaRotation * origSteeringWheelRotation;
            }
        }
    }
コード例 #21
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;
            }

            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 ==)
    }
コード例 #22
0
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is not steering
        if (state == SteeringState.NotSteering)
        {
            if (System.Math.Abs(joystick.GetAxis().y) > System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringLeft;
                }
            }

            else
            {
                state = SteeringState.NotSteering;
            }
        }

        // If state is steering forward
        else if (state == SteeringState.SteeringForward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed right and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering right
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed left and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering left
                    state = SteeringState.SteeringLeft;
                }
            }
            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y < 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringBackward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }

        else if (state == SteeringState.SteeringBackward)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            else if (System.Math.Abs(joystick.GetAxis().y) < System.Math.Abs(joystick.GetAxis().x))
            {
                // If the joystick is pressed right and the button is pressed
                if (joystick.GetAxis().x > 0.0f && button.GetPress())
                {
                    // Change state to steering right
                    state = SteeringState.SteeringRight;
                }

                // If the joystick is pressed left and the button is pressed
                else if (joystick.GetAxis().x < 0.0f && button.GetPress())
                {
                    // Change state to steering left
                    state = SteeringState.SteeringLeft;
                }
            }

            // If the joystick is pressed forward and the button is pressed
            else if (joystick.GetAxis().y > 0.0f && button.GetPress())
            {
                // Change state to steering forward
                state = SteeringState.SteeringForward;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.forward;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().y *direction *speed *Time.deltaTime;
            }
        }


        else if (state == SteeringState.SteeringRight)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward or backward and the button is pressed
            else if (System.Math.Abs(joystick.GetAxis().x) < System.Math.Abs(joystick.GetAxis().y))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (joystick.GetAxis().x < 0 && button.GetPress())
            {
                state = SteeringState.SteeringLeft;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.right;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *direction *speed *Time.deltaTime;
            }
        }

        else if (state == SteeringState.SteeringLeft)
        {
            // If the button is not pressed
            if (!button.GetPress())
            {
                // Change state to not steering
                state = SteeringState.NotSteering;
            }

            // If the joystick is pressed forward or backward and the button is pressed
            else if (System.Math.Abs(joystick.GetAxis().x) < System.Math.Abs(joystick.GetAxis().y))
            {
                // If the joystick is pressed forward and the button is pressed
                if (joystick.GetAxis().y > 0.0f && button.GetPress())
                {
                    // Change state to steering forward
                    state = SteeringState.SteeringForward;
                }

                // If the joystick is pressed backward and the button is pressed
                else if (joystick.GetAxis().y < 0.0f && button.GetPress())
                {
                    // Change state to steering backward
                    state = SteeringState.SteeringBackward;
                }
            }

            else if (joystick.GetAxis().x > 0 && button.GetPress())
            {
                state = SteeringState.SteeringRight;
            }

            // Process current steering backward state
            else
            {
                Vector3 direction = tracker.transform.right;
                direction.y = 0.0f;

                // Translate the space based on the tracker's absolute forward direction and the joystick's backward value
                space.transform.position += joystick.GetAxis().x *direction *speed *Time.deltaTime;
            }
        }
    }
コード例 #23
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;
            }
        }
    }
コード例 #24
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
            }
        }
    }
コード例 #25
0
ファイル: VirtualHand.cs プロジェクト: saayv1/Driving-Hazards
    // FixedUpdate is not called every graphical frame but rather every physics frame
    void FixedUpdate()
    {
        // If state is open
        if (state == VirtualHandState.Open)
        {
            isHit = GameObject.Find("scripts/Steering").GetComponent <Steering> ().isHit;

            // 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 || !right_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() && right_hand.triggerOngoing && right_button.GetPress())
            {
                // Fetch touched target
                target = hand.ongoingTriggers [0];
                //initialVector = hand.gameObject.transform.position- steeringWheel.transform.position;

                initialVector = (hand.gameObject.transform.position - steeringWheel.transform.position) + (right_hand.gameObject.transform.position - steeringWheel.transform.position);

                initialVector             = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);
                origSteeringWheelRotation = steeringWheel.transform.rotation;

                // Change state to LeftTurn
                state = VirtualHandState.Grabbing;
            }
            // Process current touching state
            else
            {
                //initialPosition = hand.gameObject.transform.position;

                // Nothing to do for touching
            }
        }
        // If state is LeftTurn
        else if (state == VirtualHandState.Grabbing)
        {
            // If button has been released and grasp still exists
            if (!button.GetPress() || !right_button.GetPress())
            {
                state = VirtualHandState.Open;
            }

            if (isHit)
            {
                //deltaRotation.Equals (0);
                state = VirtualHandState.Open;
                initialVector.Set(0, 0, 0);
                currentVector.Set(0, 0, 0);
                deltaRotation.Set(0, 0, 0, 0);
            }
            // Process current LeftTurn state
            else
            {
                steeringWheelNormal = steeringWheel.transform.forward;

                origSteeringWheelRotation = steeringWheel.transform.rotation;

                currentVector = (hand.gameObject.transform.position - steeringWheel.transform.position) + (right_hand.gameObject.transform.position - steeringWheel.transform.position);

                initialVector = Vector3.ProjectOnPlane(initialVector, steeringWheelNormal);

                currentVector = Vector3.ProjectOnPlane(currentVector, steeringWheelNormal);

                deltaRotation.SetFromToRotation(initialVector, currentVector);

                GameObject car = GameObject.Find("Classic_car_1955_style1");

                steeringWheel.transform.rotation = deltaRotation * origSteeringWheelRotation;

                isHit = GameObject.Find("scripts/Steering").GetComponent <Steering> ().isHit;

                initialVector = currentVector;
            }
        }
    }
コード例 #26
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
            }
        }
    }
コード例 #27
0
        void FixedUpdate()
        {
            /* Controls:
             * Throttle: W-S
             * Rudder: D-A
             * Pitch: up-down
             * Ailerons: right-left
             * D - Yaw Right
             */
            if (Pitch_Roll != null && Throttle_Yaw != null)
            {
                Vector2 pitch_roll   = Vector2.zero;
                Vector2 throttle_yaw = Vector2.zero;
                if (left_joypad.GetPress())
                {
                    Debug.Log("LEFT TRIGGERED");
                    throttle_yaw = Throttle_Yaw.GetAxis();
                    if (Mathf.Abs(throttle_yaw.x) < dead_zone_radius)
                    {
                        throttle_yaw.x = 0f;
                    }
                    if (Mathf.Abs(throttle_yaw.y) < dead_zone_radius)
                    {
                        throttle_yaw.y = 0f;
                    }
                }
                if (right_joypad.GetPress())
                {
                    Debug.Log("RIGHT TRIGGERED!");
                    pitch_roll = Pitch_Roll.GetAxis();
                    if (Mathf.Abs(pitch_roll.x) < dead_zone_radius)
                    {
                        pitch_roll.x = 0f;
                    }
                    if (Mathf.Abs(pitch_roll.y) < dead_zone_radius)
                    {
                        pitch_roll.y = 0f;
                    }
                }

                float pitch_input    = pitch_roll.y;
                float roll_input     = pitch_roll.x;
                float throttle_input = throttle_yaw.y;
                float yaw_input      = throttle_yaw.x;

                //Debug.Log("throttle_input: " + throttle_input);
                Move(pitch_input, roll_input, yaw_input, throttle_input);
            }
            else
            {
                float pitch_input    = Input.GetAxis("Elevators");
                float roll_input     = Input.GetAxis("Ailerons");
                float throttle_input = Input.GetAxis("Throttle");
                float yaw_input      = Input.GetAxis("Rudder");
                Move(pitch_input, roll_input, yaw_input, throttle_input);
            }
            //

            this.FrontLeftRotor.Rotate(0, -max_rotor_rpm * Total_Throttle * Time.deltaTime * k_Rpm_to_Dps, 0);
            this.FrontRightRotor.Rotate(0, max_rotor_rpm * Total_Throttle * Time.deltaTime * k_Rpm_to_Dps, 0);
            this.BackLeftRotor.Rotate(0, max_rotor_rpm * Total_Throttle * Time.deltaTime * k_Rpm_to_Dps, 0);
            this.BackRightRotor.Rotate(0, -max_rotor_rpm * Total_Throttle * Time.deltaTime * k_Rpm_to_Dps, 0);
            //Adjust the pitch of the sound source.
            sound_source.pitch = linear_stretch(this.Total_Throttle, 0.0f, 1.0f, 0.0f, 2.0f);
        }