Beispiel #1
0
        private void Update()
        {
            if (OVRInput.GetUp(OVRInput.Button.Two))
            {
                isMenuOpen = !isMenuOpen;

                itemMenu.SetItems(items);
                itemMenu.gameObject.SetActive(isMenuOpen);
                playerController.SetHaltUpdateMovement(isMenuOpen);
            }

            if (isMenuOpen)
            {
                Vector2 radialVector = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
                float   radialAngle  = -Mathf.Atan2(radialVector.x, radialVector.y) * Mathf.Rad2Deg;

                itemMenu.SetArrowAngle(radialAngle);

                if (OVRInput.GetUp(OVRInput.Button.One))
                {
                    character.EquipItem(itemMenu.GetSelectedItem(), EquipSlot.Left_Hand);

                    isMenuOpen = !isMenuOpen;

                    itemMenu.gameObject.SetActive(isMenuOpen);
                    playerController.SetHaltUpdateMovement(isMenuOpen);
                }
            }
        }
Beispiel #2
0
 // UpdatePlayerControllerMovement
 void UpdatePlayerControllerMovement()
 {
     if (PlayerController != null)
     {
         PlayerController.SetHaltUpdateMovement(ScenesVisible);
     }
 }
Beispiel #3
0
    //Triggers when something collides with the box
    void OnTriggerEnter(Collider other)
    {
        trigger = other.gameObject; //saves the triggering object
        if (trigger)                //if it is an object
        {
            //then save it as a Player Controller
            playerMovement = trigger.GetComponent <OVRPlayerController>();
            if (playerMovement)             //if it is player-controlled
            {
                //then halt the player movement
                playerMovement.SetHaltUpdateMovement(true);
                menu = trigger.GetComponent <OVRMainMenu>();
                if (menu)
                {
                    menu.haltMovement = true;
                }

                beginCharacterCrouch = true;                 //begin the player crouching sequence
            }
        }
    }
Beispiel #4
0
            void moveAvatar(InputAction inputAction = null)
            {
                Vector3             moveDirection       = Vector3.zero;
                float               motorDamp           = (1.0f + (forwardDampingRate * movementRate * Time.deltaTime));
                CharacterController characterController = HMDSimulator.getCamera.GetComponentInParent <CharacterController>();
                bool isGrounded = true;

                if (characterController != null)
                {
                    isGrounded = characterController.isGrounded;
                }
                else
                {
                    if (HMDSimulator.getCameraContainer.position.y > HMDSimulator.headHeight)
                    {
                        isGrounded = false;
                    }
                }

                moveThrottle.x /= motorDamp;
                moveThrottle.y  = (moveThrottle.y > 0.0f) ? (moveThrottle.y / motorDamp) : moveThrottle.y;
                moveThrottle.z /= motorDamp;

                moveDirection += moveThrottle * movementRate * Time.deltaTime;

                if (isGrounded == false && fallSpeed <= 0)
                {
                    fallSpeed = ((Physics.gravity.y * (gravityAdjustment * 0.002f)));
                }
                else if (isGrounded == false)
                {
                    fallSpeed += ((Physics.gravity.y * (gravityAdjustment * 0.002f)) * movementRate * Time.deltaTime);
                }
                else
                {
                    fallSpeed = 0f;
                }

                moveDirection.y += fallSpeed * movementRate * Time.deltaTime;

                Vector3 predictedXZ;
                Vector3 predictedWorldXZ;
                Vector3 predictedWorldLeftControllerXZ;
                Vector3 predictedWorldRightControllerXZ;
                Vector3 actualXZ;

                if (characterController != null)
                {
                    OVRPlayerController ovrPlayerController = HMDSimulator.getCamera.GetComponentInParent <OVRPlayerController>();
                    predictedXZ      = Vector3.Scale((characterController.transform.localPosition + moveDirection), new Vector3(1, 0, 1));
                    predictedWorldXZ = Vector3.Scale((characterController.transform.position + moveDirection), new Vector3(1, 0, 1));
                    if (HMDSimulator.simulateControllers)
                    {
                        predictedWorldLeftControllerXZ  = Vector3.Scale((HMDSimulator.leftController.position + moveDirection), new Vector3(1, 0, 1));
                        predictedWorldRightControllerXZ = Vector3.Scale((HMDSimulator.rightController.position + moveDirection), new Vector3(1, 0, 1));
                        if (PlayAreaManager.isMovementBoundToPlayArea && PlayAreaManager.hasImmerseumPlayArea)
                        {
                            if (PlayAreaManager.playArea.isWithinBoundary(predictedWorldXZ, predictedWorldLeftControllerXZ, predictedWorldRightControllerXZ) == false)
                            {
                                if (characterController != null && ovrPlayerController != null)
                                {
                                    ovrPlayerController.SetHaltUpdateMovement(true);
                                }
                                return;
                            }
                        }
                    }
                    if (PlayAreaManager.isMovementBoundToPlayArea && PlayAreaManager.hasImmerseumPlayArea)
                    {
                        if (PlayAreaManager.playArea.isWithinBoundary(predictedWorldXZ) == false)
                        {
                            if (characterController != null && ovrPlayerController != null)
                            {
                                ovrPlayerController.SetHaltUpdateMovement(true);
                            }
                            return;
                        }
                    }
                    characterController.Move(moveDirection);
                    actualXZ = Vector3.Scale(characterController.transform.localPosition, new Vector3(1, 0, 1));
                }
                else
                {
                    predictedXZ      = Vector3.Scale((HMDSimulator.getCamera.localPosition + moveDirection), new Vector3(1, 0, 1));
                    predictedWorldXZ = Vector3.Scale((HMDSimulator.getCamera.position + moveDirection), new Vector3(1, 0, 1));
                    if (HMDSimulator.simulateControllers)
                    {
                        predictedWorldLeftControllerXZ  = Vector3.Scale((HMDSimulator.leftController.position + moveDirection), new Vector3(1, 0, 1));
                        predictedWorldRightControllerXZ = Vector3.Scale((HMDSimulator.rightController.position + moveDirection), new Vector3(1, 0, 1));
                        if (PlayAreaManager.isMovementBoundToPlayArea && PlayAreaManager.hasImmerseumPlayArea)
                        {
                            if (PlayAreaManager.playArea.isWithinBoundary(predictedWorldXZ, predictedWorldLeftControllerXZ, predictedWorldRightControllerXZ) == false)
                            {
                                return;
                            }
                        }
                    }
                    if (PlayAreaManager.isMovementBoundToPlayArea && PlayAreaManager.hasImmerseumPlayArea)
                    {
                        if (PlayAreaManager.playArea.isWithinBoundary(predictedWorldXZ) == false)
                        {
                            return;
                        }
                    }
                    HMDSimulator.CameraRig.root.localPosition += moveDirection;
                    actualXZ = Vector3.Scale(HMDSimulator.getCamera.localPosition, new Vector3(1, 0, 1));
                }

                if (predictedXZ != actualXZ)
                {
                    moveThrottle += (actualXZ - predictedXZ) / (movementRate * Time.deltaTime);
                }

                setHasMoved(true);
            }