- Home /
[Gear VR] moving camera - no input controls work
Hello everybody,
I can't seem to be able to get the camera moving inside my Gear VR App.
Inside the desktop environment mouse and keyboard input seem to be working fine. I'm using Unity 5.2.2f1 on an S6 Edge, have downloaded and extracted the oculus mobile sdk and have android studio working. On Android, I use a bluetooth keyboard.
I've tried these approaches so far: - mouse input button 0 for the touchpad - mouse axis for the touchpad - keyboard entry wasd and arrow keys - tried to use Oculus Utilities instead
Any ideas?
My latest collection of attempts looks like this:
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
public int button = 0;
public float clickSize = 50; // this might be too small
Vector3 pos; // Use this for initialization
void Start () {
OVRTouchpad.Create();
OVRTouchpad.TouchHandler += HandleTouchHandler;
}
void HandleTouchHandler(object sender, System.EventArgs e)
{
OVRTouchpad.TouchArgs touchArgs = (OVRTouchpad.TouchArgs)e;
if (touchArgs.TouchType == OVRTouchpad.TouchEvent.SingleTap)
{
//TODO: Insert code here to handle a single tap. Note that there are other TouchTypes you can check for like directional swipes, but double tap is not currently implemented I believe.
/*if (Camera.current != null)
{
// pos = Input.mousePosition;
float moveForward = 0.001f;// Input.GetAxis("Mouse X");
float moveUpward = 0.0f;// Input.GetAxis("Mouse Y");
Vector3 camVec = Camera.current.transform.TransformVector(new Vector3(0.0f, moveUpward, moveForward));
Camera.current.transform.Translate(camVec);
}*/
transform.Translate(new Vector3(0, 0, 3.5f * Time.deltaTime));
}
}
void ClickHappened()
{
Debug.Log("CLICK!");
}
// Update is called once per frame
void Update () {
var speed = 3.5f;
/*if (Input.GetMouseButtonDown(button))
{
if (Camera.current != null)
{
// pos = Input.mousePosition;
float moveForward = 0.001f;// Input.GetAxis("Mouse X");
float moveUpward = 0.0f;// Input.GetAxis("Mouse Y");
Vector3 camVec = Camera.current.transform.TransformVector(new Vector3(0.0f, moveUpward, moveForward));
Camera.current.transform.Translate(camVec);
}
}*/
if (Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.Translate(new Vector3(-speed * Time.deltaTime, 0, 0));
}
if (Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(new Vector3(0, 0, -speed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.UpArrow))
{
transform.Translate(new Vector3(0, 0, speed * Time.deltaTime));
}
if (Input.GetMouseButtonUp(button))
{
}
}
}
Are you trying to move one of the cameras (there are two) or the OVRCameraRig? I think you can't move the cameras directly because their position is updated by the OVRCameraRig.cs script and have to move the rig.
Answer by Shnyder · Nov 13, 2015 at 05:45 PM
Edit: In the VR Overview Manual for 5.1 at "understanding the manual" it says: http://docs.unity3d.com/Manual/VROverview.html
The camera transform is overridden with the head-tracked pose. If you want to move the camera, you must attach it as a child to another game object and then move the root game object. You will need to adjust scripts that directly move the camera.
That actually brought me on the right track: I created a new project with a plane, a cube and a ball. I used the VR-Setting in 5.2 for the camera. I attached the ball to the camera and the camera to the cube. The script (without OVR-related code) was then added to the cube.
The result is that the ball sticks in front of the camera whereever I move my head, and the camera is movable with a bluetooth keyboard.
I think I'll stick with the approach of using dummy objects, as they give a simple interface while the VR SDKs might still change a lot.
Answer by NeeMan · Jun 29, 2016 at 04:44 PM
Excellent thanks! Helped me a lot, was really struggling to debug and profile my VR app.