En este momento estás viendo Problema de hacer un juego de laberinto que es control de giroscopio en Unity3D

 – Unity

Problema de hacer un juego de laberinto que es control de giroscopio en Unity3D – Unity

Problema de hacer un juego de laberinto que es control de giroscopio en Unity3D

– UnityAssets3Free

bienvenido , me llamo juansito y para hoy os traigo
esta nueva pregunta

Como título, estoy creando un juego de laberinto que permite a los jugadores controlar el laberinto mediante un giroscopio móvil, no tuve este problema en la plataforma iOS. Cuando la plataforma cambia a Android, Input.gyro.attitude siempre es (x, y, z, -0.6), necesito girar mi teléfono 90 grados para que la actitud sea (x, y, z, -1), y esto es lo que quiero. ¿Cómo puedo estar seguro de que el teléfono del jugador apunta en qué dirección al principio, la actitud es siempre (x, y, z, -1)?

Puedo configurar gyro.enable=false para restablecer el giroscopio, pero Android no puede

Aquí está el video del problema, por favor, eche un vistazo a mis problemas.
https://drive.google.com/file/d/1sed6qqFVFUbg4TJXqfM6GviVFnySa-tQ/view?usp=sharing

(Perdón por mi peor gramática e inglés)

Así tomo el giroscopio del teléfono y hago girar el laberinto


using UnityEngine;

public class GyroManager : Singleton<GyroManager>

    [Header("Gryo")]
    [SerializeField] private Gyroscope gyro;
    [SerializeField] private Quaternion phoneQuaternion;
    [SerializeField] private float hardFixedZ;
    public bool gyroActive;

    private void Update()
    
        if (gyroActive && GameController.Instance.isGameStart)
        
            phoneQuaternion =  GyroToUnity(gyro.attitude);
        
    
    public void EnableGyro()
    
        //reture if Gyro already active
        if (gyroActive)
            return;

        //Check whether or not users' phone hasn't garrow's scope in it
        if (SystemInfo.supportsGyroscope)
        
            Debug.Log("Gyro is support on this device");
            gyro = Input.gyro;
            gyro.enabled = true;
            gyroActive = gyro.enabled;
        
        else
        
            Debug.LogWarning("Gyro is not support on this device");
        

    

    public Quaternion GetPhoneGyro()
    
        return phoneQuaternion;
    

    public Quaternion GyroToUnity(Quaternion q)
    
        return new Quaternion(q.x, 0, q.y, -q.w);
    

    protected void OnGUI()
    
        GUI.skin.label.fontSize = Screen.width / 20;

        if (gyroActive)
        
            GUILayout.Label("Orientation: " + Screen.orientation);
            GUILayout.Label("input.gyro.attitude: " + phoneQuaternion);
            GUILayout.Label("iphone width/height/font: " + Screen.width + " : " + Screen.height + " : "+ GUI.skin.label.fontSize);
        
    

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowGyro : MonoBehaviour

    // Update is called once per frame
    void Update()
    
        if (GyroManager.Instance.gyroActive)
        
            transform.rotation = GyroManager.Instance.GetPhoneGyro();
        
    

0

nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias

eso es todo,espero que te funcione

Deja una respuesta