Exemple #1
0
        void UpdateMove()
        {
            Vector3 moveDir;

            if (m_directionMode == eMoveDirectionMode.GAZE)
            {
                moveDir = m_headRef.forward;
            }
            else
            {
                moveDir = m_activeController.GetFaceDirection();
            }

            if (m_activeController.GetButtonDown((Valve.VR.EVRButtonId)m_buttonToPress))
            {
                m_agent.Move(moveDir * m_runSpeed * Time.deltaTime);
            }
            else
            {
                m_agent.Move(moveDir * m_walkSpeed * Time.deltaTime);
            }
        }
Exemple #2
0
        void Update()
        {
            if (leftController.GetButton((Valve.VR.EVRButtonId)runButton) || rightController.GetButton((Valve.VR.EVRButtonId)runButton) &&
                !isToggle)
            {
                zVelLeft  = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).z;
                zVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).z;

                xVelLeft  = vrRig.s_head.transform.InverseTransformDirection(leftController.getDeviceVelocity()).x;
                xVelRight = vrRig.s_head.transform.InverseTransformDirection(rightController.getDeviceVelocity()).x;

                if (swingingArmBack && motionType != eMotionType.BREAST_STROKE)
                {
                    float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x;
                    float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y;
                    float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z;

                    swingForce = Mathf.Max(posX, posY, posZ) * swingForceMultiplier;

                    agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *moveSpeed *swingForce *Time.deltaTime);
                }
                else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE)
                {
                    switch (swimSettings)
                    {
                    case eSwimSettings.FREE: {
                        agent.enabled = false;

                        float posX = (leftController.getDeviceVelocity().x < 0) ? leftController.getDeviceVelocity().x * -1 : leftController.getDeviceVelocity().x;
                        float posY = (leftController.getDeviceVelocity().y < 0) ? leftController.getDeviceVelocity().y * -1 : leftController.getDeviceVelocity().y;
                        float posZ = (leftController.getDeviceVelocity().z < 0) ? leftController.getDeviceVelocity().z * -1 : leftController.getDeviceVelocity().z;

                        transform.root.position += transform.forward / (moveSpeed * 12) * (Mathf.Max(posX, posY, posZ) * 4);
                        break;
                    }

                    case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break;
                    }
                }

                switch (motionType)
                {
                case eMotionType.ARM_SWING:                     UpdateArmSwing();                        break;

                case eMotionType.SKIING:                                        UpdateSkiing();                                  break;

                case eMotionType.BREAST_STROKE: UpdateBreastStroke();            break;

                default: Debug.LogWarning("Somehow you have no motion type set??"); break;
                }
            }
            else if (leftController.GetButtonDown((Valve.VR.EVRButtonId)runButton) ||
                     rightController.GetButtonDown((Valve.VR.EVRButtonId)runButton) && isToggle)
            {
                toggleOn = !toggleOn;
            }

            if (isToggle)
            {
                if (toggleOn)
                {
                    if (swingingArmBack && motionType != eMotionType.BREAST_STROKE)
                    {
                        agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed);
                    }
                    else if (swingingArmBack && motionType == eMotionType.BREAST_STROKE)
                    {
                        switch (swimSettings)
                        {
                        case eSwimSettings.FREE: {
                            agent.enabled            = false;
                            transform.root.position += transform.forward / (moveSpeed * 12);
                            break;
                        }

                        case eSwimSettings.LOCKED_TO_NAV_MESH: agent.Move(transform.root.GetComponent <VRLocomotionRig>().s_head.transform.forward *Time.deltaTime *moveSpeed); break;
                        }

                        switch (motionType)
                        {
                        case eMotionType.ARM_SWING:                     UpdateArmSwing();                        break;

                        case eMotionType.SKIING:                                        UpdateSkiing();                                  break;

                        case eMotionType.BREAST_STROKE: UpdateBreastStroke();            break;

                        default: Debug.LogWarning("Somehow you have no motion type set??"); break;
                        }
                    }
                }
                else
                {
                    agent.velocity = Vector3.zero;
#if UNITY_5_6
                    agent.isStopped = true;
#else
                    agent.Stop();
#endif
                }
            }
        }
Exemple #3
0
        void Update()
        {
            if (!disableButton)
            {
                if (!isToggle)
                {
                    if (m_leftController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_pressing         = true;
                        m_activeController = m_leftController;
                    }
                    else if (m_rightController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_pressing         = true;
                        m_activeController = m_rightController;
                    }

                    if (m_pressing == true && (m_activeController.GetButtonUp((Valve.VR.EVRButtonId)buttonToPress)))
                    {
                        m_pressing         = false;
                        m_activeController = null;
                        Debug.Log("Stop Tracking");
                        m_agent.velocity = Vector3.zero;
#if UNITY_5_6
                        m_agent.isStopped = true;
#else
                        m_agent.Stop();
#endif
                        m_bobState = BobState.STILL;
                    }
                }
                else
                {
                    if (m_leftController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress) ||
                        m_rightController.GetButtonDown((Valve.VR.EVRButtonId)buttonToPress))
                    {
                        m_toggleOn = !m_toggleOn;
                    }
                }
            }
            else
            {
                m_pressing         = true;
                m_activeController = m_leftController;
            }

            if (isToggle)
            {
                if (m_toggleOn)
                {
                    m_pressing         = true;
                    m_activeController = m_leftController;
                }
                else
                {
                    m_pressing         = false;
                    m_activeController = null;
                    m_agent.velocity   = Vector3.zero;
#if UNITY_5_6
                    m_agent.isStopped = true;
#else
                    m_agent.Stop();
#endif
                    m_bobState = BobState.STILL;
                }
            }

            if (TrackingHeadbob())
            {
                CheckForHeadBob();
            }

            UpdateBobStates();
        }