Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
neurobio.unibielefeld's avatar
1 year ago

CenterEyeCamera out of boundary play area not registered in Unity

Hi everybody,

I am designing a game where players actually move through space to collect targets. If they get too close to the Quest boundary I want to track that in Unity and trigger some behaviour. My code looks like this:

 

using unibi.homingtask.logistics;
using UnityEngine;

namespace unibi.vnt.guidance
{
    public class OutOfBoundsChecker : MonoBehaviour
    {
        [SerializeField] private TrialDataManager trialDataManager;
        [SerializeField] private PlayerManager playerManager;
        [SerializeField] private Camera playerCamera;
        [SerializeField] private AudioManager audioManager;
        private OVRBoundary boundary;

        // Start is called once before the first execution of Update after the MonoBehaviour is created
        void Start()
        {
            boundary = new OVRBoundary();        
        }

        // Update is called once per frame
        void Update()
        {
            checkOutOfBounds();
            //if (Input.GetKeyDown(KeyCode.P))
            if (OVRInput.Get(OVRInput.Button.Three))
            {
                Debug.Log("bounds: button triggered out of bounds");
                triggerOutOfBounds();       
            }
        }

        private void checkOutOfBounds()
        {
            if (OVRManager.instance ==  null)
            {
                Debug.Log($"bounds: ovr manager NOT initialized");
            }
            else
            {
                Debug.Log($"bounds: ovr manager is initialized");
            }

            if (OVRManager.boundary != null)
            {
                if (OVRManager.boundary.GetConfigured())
                {
                    Debug.Log($"bounds: configured");
                }
                else
                {
                    Debug.Log($"bounds: NOT configured");
                }
            }
            else
            {
                Debug.Log($"bounds: NOT initiaialized");
            }


            Vector3 centerEyePosition = playerCamera.transform.position;
            Debug.Log($"bounds: center eye position {centerEyePosition}");
            // Check if the center eye is close to the boundary
            OVRBoundary.BoundaryTestResult result = boundary.TestPoint(centerEyePosition, OVRBoundary.BoundaryType.OuterBoundary);
            Debug.Log($"bounds: current distance: {result.ClosestDistance} at point {result.ClosestPoint}");

            if (result.IsTriggering)
            {
                Debug.Log("bounds: Center eye is close to the boundary!");
                triggerOutOfBounds();
            }
            else
            {
                Debug.Log("bounds: Center eye safe!");
            }
        }

        private void triggerOutOfBounds()
        {
            trialDataManager.TrialData.OutOfBounds = true;
            playerManager.OnPlayerSteppedOutOfBounds();
            audioManager.playOutOfBounds();          
        }
    } 
}

 

I assigned the CenterEyeCamera of my OVRCameraRig to playerCamera.

My Meta SDK All in One is updated (71.0.0), so is the OS (v72) on my Meta Quest 3. The log is telling me that "ovr manager is initialized", that it is "configured", and that the center eye position is changing the position as expected.

However, the triggerOutOfBounds() behaviour is never triggered automatically because 'result.ClosestDistance' never changes from 0.0 and 'result.ClosestPoint' is always (0.00, 0.00, 0.00).

There is only one instance of OVRManager in my scene, it is attached to an Empty GameObject.

As expected the X-Button (OVRInput.Button.Three) triggers the triggerOutOfBounds()-function as expected.

 

Does anybody encountered problems with registering boundary crossings in Unity or has any tips where to debug?

1 Reply

Replies have been turned off for this discussion