0
\$\begingroup\$

I'm trying to make a simple VR cardboard game using Google VR SDK for Unity. I'm really confused about the problem as my title. Will the values got from

GvrViewer.Instance.HeadPose.Orientation.x;

change when the orientation of smartphone change from Portrait to Landscape Left/Right?

The following code works in Unity demo (after press play button and use alt+right-click to trigger head movement simulation), but I don't have a cardboard so I'm not sure whether it will still work on smartphone with landscape left or right attached to a cardboard.

private void Update()
{
    // forward if the value is positive.
    float forwardValue = GvrViewr.Instance.HeadPose.Orientation.x;
    // turn left if the value is negative.
    float turnValue = GvrViewr.Instance.HeadPose.Orientation.y;
}

private void Move()
{
    Vector3 movement = transform.forward * forwardValue * m_Speed * Time.deltaTime;

    // Apply this movement to the rigidbody's position.
    m_Rigidbody.MovePosition(m_Rigidbody.position + movement);
}

private void Turn()
{

    // Determine the number of degrees to be turned based on the input, speed and time between frames.
    float turn = turnValue * m_TurnSpeed * Time.deltaTime;

    // Make this into a rotation in the y axis.
    Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);

    // Apply this rotation to the rigidbody's rotation.
    m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
}
\$\endgroup\$
  • 1
    \$\begingroup\$ This looks like a quaternion field. Accessing an individual component of a quaternion is typically not a meaningful measure of direction. Can you clarify what you're trying to accomplish with this code? There may be more robust ways to get that outcome. \$\endgroup\$ – DMGregory Dec 3 at 15:44
  • \$\begingroup\$ @DMGregory: I think you're right, although I don't know what is quaternion... \$\endgroup\$ – Niing Dec 3 at 15:55
  • \$\begingroup\$ Did you consider looking it up? It's not a secret code-word, it's a standard data structure used widely in game development. \$\endgroup\$ – DMGregory Dec 3 at 16:02
  • \$\begingroup\$ @DMGregory: I've updated it again, I think my problem is simple and not related to math... \$\endgroup\$ – Niing Dec 3 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.