Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Kothe's avatar
Kothe
Honored Guest
12 years ago

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.

8 Replies

Replies have been turned off for this discussion
  • 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();
    }
    }
  • 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();
    }
    }
  • Kothe's avatar
    Kothe
    Honored Guest
    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
  • drash's avatar
    drash
    Heroic Explorer
    You might be using a version of the SDK where ResetOrientation requires a sensor #. Try changing it from ResetOrientation() to ResetOrientation(0).
  • 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".
  • 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".