Ich mache eine Gyroskop-fähige App für Android/iOS, wo Sie Ihr Gyroskop verwenden können, um sich umzusehen. Ich möchte, dass der Player seine Kameraposition zurückstellt (die Szene vor dem Gerät), aber ich kann kein System dafür finden. HierUnity Gyroskop Kamera-Position zurücksetzen (wie oculus recenter Kamera)
ist der Code für umsah:
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour {
void Start() {
if (SystemInfo.supportsGyroscope) {
Input.gyro.enabled = true;
//Create parent object and set this object's parent to that
GameObject camParent = new GameObject ("CamParent");
camParent.transform.position = transform.position;
transform.parent = camParent.transform;
// Rotate the parent object by 90 degrees around the x axis
camParent.transform.Rotate (Vector3.right, 90);
}
}
void Update() {
if (SystemInfo.supportsGyroscope) {
Quaternion rotation = new Quaternion (Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
transform.localRotation = rotation;
}
}
void OnGUI() {
if (SystemInfo.supportsGyroscope) {
GUILayout.Label (transform.localRotation.ToString());
GUILayout.Label (transform.parent.rotation.ToString());
if (GUILayout.Button ("Recenter View")) {
//RECENTER THE CAMERA VIEW
}
}
}
}
nicht funktioniert, macht die Ansicht, alle seitwärts und verkorkste –
Vielleicht haben Sie den Algorithmus falsch, oder was? –
Mein Android-Gerät ist kaputt gegangen und kann dies momentan nicht beheben. Bitte versuchen Sie es in der Zwischenzeit: https://gist.github.com/chanibal/baf46307c4fee3c699d5 Sie können die Rotation umkehren (ändern Sie Zeile 23 in 'transform.localRotation = Quaternion.Inverse (Quaternion.Inverse (origin) * Input .gyro.attitude); ') –