In general, you just need to make sure that the camera and the player’s body rotate in the same way, because without this you can’t do normal walking, because the axes remain in place, and if you turn around in VR, for example, by 180 degrees, it turns out if you click “go ahead” "- we go back.
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); } } }