Я делаю приложение с поддержкой гироскопа для Android и ios, где вы можете использовать свой гироскоп, чтобы осмотреться. Я бы хотел, чтобы плеер сбросил свою позицию камеры (сцену ретранслятора Infront устройства), но я не могу заставить систему работать для этого.Unity Gyroscope Сброс положения камеры (например, камера заднего обзора oculus)
Вот код для озираясь:
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
}
}
}
}
Не работает, делает вид сбоку и все перепутались –
Может быть, вы получили алгоритм неправильно или что-то? –
Мое устройство Android сломалось и не может отлаживать это на данный момент. Попробуйте это время: https://gist.github.com/chanibal/baf46307c4fee3c699d5 Возможно, вы захотите инвертировать поворот (смените строку 23 на 'transform.localRotation = Quaternion.Inverse (Quaternion.Inverse (origin) * Input .gyro.attitude); ') –