Skip to main content
Participant
May 29, 2014

Reset Orientation

Hi.
I have seen some post about reset the view, but I don´t understand the way they do. I not a programer.
I would like to find a simple script to triger then reset the rotation of the OWR camera controller.

The situation is this: When the OWR camera control exceeds a specific degree reset it rotation value.

Thanks in advance.
    This topic has been closed for replies.

    8 replies

    Inspiring
    May 30, 2014
    Here is one way to do it. Copy and paste the following code into a new C# script in your project and then attach the script to a GameObject in your scene.

    using UnityEngine;

    public class Reset : MonoBehaviour {
    // Update is called once per frame
    void Update () {
    if (Input.GetKeyDown(KeyCode.R))
    OVRDevice.ResetOrientation();
    }
    }
    Inspiring
    May 30, 2014
    The previous code would reset the orientation when you pressed "R". To reset when the player has turned farther than "MaxRotation", try this:

    using UnityEngine;

    public class Reset : MonoBehaviour {
    public float MaxRotation = 90f;

    // Update is called once per frame
    void Update () {
    Vector3 pos = Vector3.zero;
    Quaternion rot = Quaternion.identity;
    OVRDevice.GetCameraPositionOrientation(ref pos, ref rot);
    if (!(rot.eulerAngles.y < MaxRotation || 360f - rot.eulerAngles.y < MaxRotation))
    OVRDevice.ResetOrientation();
    }
    }
    KotheAuthor
    Participant
    June 2, 2014
    Both very useful .

    THX
    KotheAuthor
    Participant
    June 4, 2014
    Hi, I find this errors on the scripts

    Assets/PREFAB/RESET.cs(7,35): error CS1501: No overload for method `ResetOrientation' takes `0' arguments

    Assets/PREFAB/Reset_2.cs(3,14): error CS0101: The namespace `global::' already contains a definition for `Reset'

    and the.... All compiler errors must be fixed before...

    What I am doing wrong ?

    Thx
    Inspiring
    June 4, 2014
    You might be using a version of the SDK where ResetOrientation requires a sensor #. Try changing it from ResetOrientation() to ResetOrientation(0).
    Titans of Space PLUS for Quest is now available on DrashVR.com
    Inspiring
    June 4, 2014
    If the class name "Reset" conflicts with something else in your project, you could also rename that to "ResetCamera". You'll need to rename the script to "ResetCamera.cs".
    Up and Coming
    October 4, 2014
    Thank you VRDave!

    Here is a modified version of the reset orientation script that resets when any key is pressed.

    using UnityEngine;

    public class ResetAnyKey : MonoBehaviour {
    // Update is called once per frame
    void Update () {
    if (Input.anyKeyDown)
    OVRDevice.ResetOrientation();
    }
    }


    I'm using it within the 'Health and Safety Warning' display so as a user clears the warning they go into the menu facing the proper direction. The file name should be "ResetAnyKey.cs".
    Cubicle Ninjas Custom VR App Development Guided Meditation VR for Rift, Gear, and Go
    October 6, 2014
    Thanks for the scripts!