- Home /
VR camera rotation
I'm trying to do a first-person camera controller for Gear VR and I'm having some problems with the rotation. How it should work: When mouse button is held down, the camera moves in the direction that it's facing. This works fine while testing in Unity, but not when testing with the Gear VR. Unity automagically tracks the head rotation and rotates the camera according to that. However, the headtracking doesn't seem to "really" change the rotation of the camera, since the direction of the movement doesn't change. Script for the movement:
Vector3 movement = new Vector3();
movement.z = Input.GetAxis("Vertical");
transform.Translate(movement * Time.deltaTime * moveSpeed);
So when I hold the touchpad, it moves along the camera's (or the camera's parent object's) z-axis, no matter where I'm looking at. This has troubled me for a few days now and I just can't get it working.
(If you know the VR horror game Affected: The Manor, that's the kind of movement system that I'm trying to achieve. )
Answer by Tamms · Mar 11, 2017 at 10:16 AM
I found a way around this, from this tutorial. I added a Character Controller component for the CameraContainer object, and added the following script for the CameraContainer:
public class VRcameraMovement : MonoBehaviour {
public Transform vrCamera;
public float moveSpeed = 5.0f;
private CharacterController CharCont;
// Use this for initialization
void Start () {
CharCont = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0))
{
Vector3 forward = vrCamera.TransformDirection(Vector3.forward);
CharCont.SimpleMove(forward * moveSpeed * Time.deltaTime);
}
}
}
Your answer
Follow this Question
Related Questions
How can ı attach my camera to object for fps game ? 0 Answers
How to stop 3rd person camera going throught walls ? 1 Answer
Smooth Follow cam; how to keep camera close, but still retain sideways lag/lerp 1 Answer
Footstep sounds system with a Vr touchpad movement system 1 Answer
Panning and Rotating a Camera 0 Answers