Вообще, просто нужно сделать так, что бы камера и тело игрока поворачивались одинаково, ибо без этого нельзя сделать нормальную ходьбу, потому что оси остаются на своем месте, и если в VR повернуться, например на 180 градусов - получается, если нажать "идти вперед" - мы идем назад.
GyroControl.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GyroControl : MonoBehaviour
{
private bool gyroEnabled;
private Gyroscope gyro;
private GameObject cameraContainer;
private Quaternion rot;
public GameObject cam;
private void Start()
{
//cameraContainer = new GameObject ("Camera Container");
//cameraContainer.transform.position = transform.position;
//transform.SetParent (cameraContainer.transform);
gyroEnabled = EnableGyro ();
//GameObject.Find ("Camera Container").transform.rotation = Quaternion.Euler (0f,90f,0f);
//transform.SetParent(player.transform);
}
private bool EnableGyro()
{
if (SystemInfo.supportsGyroscope)
{
gyro = Input.gyro;
gyro.enabled = true;
//cameraContainer.transform.rotation = Quaternion.Euler (90f, 90f, 0f);
rot = new Quaternion (0, 0, 1, 0);
return true;
}
return false;
}
private void Update()
{
if (gyroEnabled)
{
transform.localRotation = gyro.attitude * rot;
//player.transform.localRotation = transform.localRotation;
}
}
}
Movement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Movement : MonoBehaviour {
Rigidbody rb;
public Camera m_camera;
public float speed = 3f;
public float jumpHeight = 3f;
// Use this for initialization
void Start () {
rb = GetComponentInChildren <Rigidbody>();
}
// Update is called once per frame
void Update () {
//transform.localRotation = m_camera.transform.localRotation;
}
private void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 tempVect = new Vector3(horizontal, 0, vertical);
tempVect = tempVect.normalized * speed * Time.deltaTime;
rb.MovePosition(transform.position + tempVect);
if (Input.GetKeyDown(KeyCode.Joystick1Button0) || Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(new Vector3(0, jumpHeight, 0), ForceMode.Impulse);
}
}
}