Question by
ljhs · Jun 04, 2019 at 06:14 PM ·
movemain camera
Move forward camera using mobile inclination
Hi. I am creating a game in virtual reality from Unity. The problem is that I want the camera to advance when the user tilt the cell x degrees. That is, the viewfinder camera advances in the direction of inclination. I have seen that some people occupy the character controller, but when I tilt the cell phone, the camera does not advance. Could someone help me with this? This is the main code:
I'm not using any specific library, I'm just taking "build and run" directly on my android device.
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Movecharacter : MonoBehaviour {
public Transform vrCamera;
public float toogleAngle=30.0f;
public float speed=3.0f;
public bool moveForward;
public Quaternion rotation;
private CharacterController cc;
void Start () {
Input.gyro.enabled = true; //
cc = GetComponent<CharacterController> ();
}
void Update () {
Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
rotation = new Quaternion(0.5f, 0.5f, -0.5f, 0.5f) * Input.gyro.attitude * new Quaternion(0, 0, 1, 0);
if (posiciones.x < -0.25f) {
moveForward = true;
} else {
moveForward = false;
}
if (moveForward) {
Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
cc.SimpleMove (forward * speed);
}
}
}
Comment