質問編集履歴
2
文章の補足
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
unityのcardboard GoogleVRで
|
3
|
-
InputTracking.disablePositionalTrackingを使ってカメラを起動時に固定す
|
3
|
+
InputTracking.disablePositionalTrackingを使ってカメラを起動時に固定したいです。できるのであるのなら他の方法でもかまいません。
|
4
|
+
回答よろしくお願いします。
|
4
5
|
|
5
6
|
図1 スマホの画面の図
|
6
7
|

|
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -58,8 +58,13 @@
|
|
58
58
|
・InputTracking.disablePositionalTrackingの値をtrueにしたりfalseにしたりした。
|
59
59
|
・起動時のスマホの方向を反転させた物をVRカメラの親オブジェクトに入れてカメラの傾きを打ち消そうとしたが見当違いな方へいってしまう。VRカメラオブジェクトの向きで同様のことをしてもだめでした。
|
60
60
|
以下VRカメラの親のオブジェクトのスクリプト
|
61
|
-
|
61
|
+
|
62
62
|
```C#
|
63
|
+
//3Dシューティングゲームのカメラの親ゲームオブジェクトのソースコードです
|
64
|
+
|
65
|
+
//カメラの位置を引く
|
66
|
+
using System.Collections;
|
67
|
+
using System.Collections.Generic;
|
63
68
|
using UnityEngine;
|
64
69
|
using UnityEngine.VR;
|
65
70
|
using System;
|
@@ -75,6 +80,43 @@
|
|
75
80
|
difference = transform.position;
|
76
81
|
differenceZ = difference.z;
|
77
82
|
//カメラが今向いてる向きを取得
|
83
|
+
kamera = GameObject.FindWithTag("MainCamera");
|
84
|
+
//反転させる
|
85
|
+
Quaternion hanten=Quaternion.Euler(-kamera.transform.rotation.x,-kamera.transform.rotation.y,kamera.transform.rotation.z);
|
86
|
+
transform.rotation = hanten;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Update is called once per frame
|
90
|
+
int count;
|
91
|
+
void Update()
|
92
|
+
{
|
93
|
+
//プレイヤー機にカメラが追従するようになっている
|
94
|
+
if (GameObject.FindWithTag("player") == true)
|
95
|
+
{
|
96
|
+
Vector3 vecP = GameObject.FindWithTag("player").transform.position;
|
97
|
+
Vector3 vec3 = transform.position;
|
98
|
+
vec3.z = vecP.z+differenceZ;
|
99
|
+
transform.position = vec3;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
//スマホの方向から
|
105
|
+
using UnityEngine;
|
106
|
+
using UnityEngine.VR;
|
107
|
+
using System;
|
108
|
+
|
109
|
+
public class CameraControl : MonoBehaviour {
|
110
|
+
public Vector3 difference;
|
111
|
+
float differenceZ;
|
112
|
+
|
113
|
+
GameObject kamera;
|
114
|
+
|
115
|
+
// Use this for initialization
|
116
|
+
void Start() {
|
117
|
+
difference = transform.position;
|
118
|
+
differenceZ = difference.z;
|
119
|
+
//カメラが今向いてる向きを取得
|
78
120
|
Vector3 trackingPos =
|
79
121
|
InputTracking.GetLocalPosition(VRNode.CenterEye);
|
80
122
|
|