0
votes

Versions: Unity v2019.2.4f1, Oculus Utilities v1.41.0, OVRPlugin v1.41.0, SDK v1.42.0

I am in the process of creating an Oculus Rift game where the player can use buttons to toggle between walking around on the ground and looking around in a bird's eye view of the environment. To accomplish this, I am using the following script to toggle between two different OVRPlayerControllers, one positioned on the ground and one positioned in the air looking down:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraSwitcher : MonoBehaviour

{
    public GameObject firstPersonCameraPrefab;
    public GameObject overheadCameraPrefab;

    void Update()
    {

        bool isDownOne = false;
        bool isDownThree = false;

        isDownOne = OVRInput.GetDown(OVRInput.Button.One);
        isDownThree = OVRInput.GetDown(OVRInput.Button.Three);


        if (isDownOne || isDownThree)
        {
            switchCam();
        }

    }

    public void switchCam()
    {

        overheadCameraPrefab.SetActive(!overheadCameraPrefab.activeInHierarchy);
        firstPersonCameraPrefab.SetActive(!firstPersonCameraPrefab.activeInHierarchy);

    }
}

At the start of the game, the first person player is active, and the overhead player is not active. When I use this script, the headset toggles between looking through the two cameras. However, the connection between the game and the movement controls on the controllers gets severed after the first switch. When I toggle back down to the ground, I can no longer use my controllers to move my player around.

How can I switch between players and keep the movement controls in tact?

1

1 Answers

0
votes

This is because you have more than 1 OVRManager in your scene, the prefab OVRCameraRig has 1 attached, so if you have more than one of this prefabs, like 2 players, Oculus won't work correctly.

Put the component in an empty prefab that never turns off, and set switch between your player controllers freely.