- Home /
Problems with Gyroscope VR Car Game
Hello to all,
I am developing a Car game but i have a problem with the camera and the Car, i have a parent object that controls both Cameras and i attach that Object to the Car.
The problem is when i move the car to any direction, the camera stays in the same position, instead of not change the rotation.
this is the code that i am using.
// Code
public GameObject Contenedor; private GameObject VRCamaras; private float PosicionInicialY = 0f; private float PosicionDelGyroEnY = 0f; private float CalibrarEnLaPosicionY = 0f;
public bool SeInicioElJuego;
void Start()
{
VRCamaras = this.gameObject;
Input.gyro.enabled = true;
PosicionInicialY = VRCamaras.transform.eulerAngles.y;
}
void Update()
{
if (SeInicioElJuego == true)
{
Invoke("AnclarObjeto", .2f);
Invoke("CalibrarEnPosicionY", 0.5f);
SeInicioElJuego = false;
}
//this.transform.Rotate(0, Contenedor.transform.localRotation.y,0);
AplicarRotacionDelGiroscopio();
AplicarCalibracion();
}
void AnclarObjeto()
{
this.transform.SetParent(Contenedor.transform);
}
void AplicarRotacionDelGiroscopio()
{
VRCamaras.transform.rotation = Input.gyro.attitude;
VRCamaras.transform.Rotate(0f, 0f, 180f, Space.Self);
VRCamaras.transform.Rotate(90f, 180f, 0f, Space.World);
PosicionDelGyroEnY = Contenedor.transform.eulerAngles.y;
}
public void CalibrarEnPosicionY()
{
CalibrarEnLaPosicionY = PosicionDelGyroEnY - PosicionInicialY;
// Debug.Log("Posición en y Contenedo -> " + PosicionDelGyroEnY);
// Debug.Log("Posición en y -> " + PosicionInicialY);
}
void AplicarCalibracion()
{
VRCamaras.transform.Rotate(0f, CalibrarEnLaPosicionY, 0f, Space.World);
}
Your answer
Follow this Question
Related Questions
How would I make a ListChangedEvent? 1 Answer
Proplem with position reset script of certain object 0 Answers
Unity 3D: How to make the gameobject speed increase continuously on tapping quickly? 1 Answer
Collider not registering hits? 4 Answers
Spawning 3D Objects according to Data at JSON Matrix 0 Answers