public void ResetPointOfView()
        {
            if (!isInPersonalCamera)
            {
                return;
            }

            // SetPointOfViewの時に記録した位置に戻す、CharacterControllerを再度有効化
            if (!recordedPosition.HasValue || !recordedRotation.HasValue)
            {
                return;
            }

            if (enterDeviceType == EnterDeviceType.VR)
            {
                PlayerTransform.SetPositionAndRotation(recordedPosition.Value, recordedRotation.Value);
            }
            else
            {
                CameraTransform.SetPositionAndRotation(recordedPosition.Value, recordedRotation.Value);
            }

            playerController.ActivateCharacterController(true);
            isInPersonalCamera = false;
        }
Example #2
0
        // updates player position and the current tile variable
        private void UpdatePlayerPosition(Tile[,] tiles, int tileCoordX, int tileCoordY)
        {
            if (this.GetComponent <BoxCollider>() != null)
            {
                CurrentTile = tiles[tileCoordX, tileCoordY];

                Transform tileTransform = CurrentTile.instance.GetComponent <Transform>();
                Bounds    playerBounds  = this.GetComponent <BoxCollider>().bounds;
                Bounds    tileBounds    = CurrentTile.instance.GetComponent <BoxCollider>().bounds;
                // put player at center of the tile
                Vector3 playerPos = new Vector3(tileTransform.position.x, PlayerTransform.position.y, tileTransform.position.z);
                PlayerTransform.SetPositionAndRotation(playerPos, Quaternion.identity);
            }
        }
Example #3
0
        // initializes the current tile of the player and sets the position of the player to the center of the starting tile
        private void SetPlayerStartPos()
        {
            if (this.GetComponent <BoxCollider>() != null)
            {
                // init starting location
                this.CurrentTile = TileMap.tiles[this.startX, this.startY];

                Transform tileTransform = CurrentTile.instance.GetComponent <Transform>();
                Bounds    playerBounds  = this.GetComponent <BoxCollider>().bounds;
                Bounds    tileBounds    = CurrentTile.instance.GetComponent <BoxCollider>().bounds;
                // put player at center of the tile
                Vector3 playerPos = new Vector3(tileTransform.position.x, CalculatePlayerYPos(playerBounds, tileBounds, PlayerTransform.localScale.y), tileTransform.position.z);
                PlayerTransform.SetPositionAndRotation(playerPos, Quaternion.identity);
            }
        }
        public void SetPointOfView(Transform targetPoint)
        {
            isInPersonalCamera = true;
            // 位置を記録した後PersonalCameraの位置に移動、CharacterControllerを無効化する
            if (enterDeviceType == EnterDeviceType.VR)
            {
                recordedPosition = PlayerTransform.position;
                recordedRotation = PlayerTransform.rotation;
                // OpenVRのカメラの高さがそのまま視点の高さになるので、 見せたい視点の高さ(y) - OpenVRによるカメラの高さ(local y)をしてやることで、視点の視線の高さにする
                var targetPosition = new Vector3(targetPoint.position.x, targetPoint.position.y - CameraTransform.localPosition.y, targetPoint.position.z);
                PlayerTransform.SetPositionAndRotation(targetPosition, targetPoint.rotation);
            }
            else
            {
                recordedPosition = CameraTransform.position;
                recordedRotation = CameraTransform.rotation;
                CameraTransform.SetPositionAndRotation(targetPoint.position, targetPoint.rotation);
            }

            playerController.ActivateCharacterController(false);
        }