01-08-2020 10:15 PM
Solved! Go to Solution.
06-12-2021 06:26 PM
I absolutely agree and I also hate having to implement hacks for things that IMO should be handled by the Oculus framework. Yes it's meant for subsequent recentering events but you might be able to adapt it for the initial alignment since in either case you have to deal with OVRManager.boundary geometries. I admit I haven't had a deep look at either issue yet since I'm still working on core gameplay... but I'm hoping to come up with a cleaner solution to both issues before release. If I find/develop anything I'll definitely share it here.
06-12-2021 06:40 PM
I just reached out to Oculus Developer support. Hopefully they can help me in time, and I'll post here any solutions they might have.
06-13-2021 05:51 AM
My way of doing it works for the initial centering of the play area and subsequent re-centering as well. The way I have do it is by binding it to the re-centering event when the level is loaded. I'm not currently able to get to my computer until later today. When I do get to my computer, I can post some code snippets here to show how I have done it.
06-21-2021 05:07 PM
Sorry about taking so long to get this posted. What I did to center the world is as follows
The way you add a function to the enforcer is simply done as such:
enforcer.TrackingChanged += UpdateCenter;
in this, enforcer is the GuardianBoundaryEnforce and UpdateCenter is the function that will help center the player.
UpdateCenter is as follows:
private void UpdateCenter()
{
if(OVRManager.boundary.GetConfigured())
{
boundary = OVRManager.boundary.GetDimensions(OVRBoundary.BoundaryType.PlayArea);
points = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.PlayArea);
CenterPlayer();
}
}
I personally split up the method into two just because my other method is longer and I didn't want it surrounded in the if statement of the OVRManager. That is in place to make sure we actually have a Boundary and is working correctly. If it wasn't we wouldn't be able to get any points. So now for the main show. We center the world around the guardian. To do this, I took the points from the OVRManager and put converted them to local space by putting them onto 4 points that my script creates. I them find the center between all the points and have it face forwards. from there I am able to set the rotation of the gameObject contating all the world objects to that rotation and position. Then everything is rotated.
private void CenterPlayer()
{
point1.transform.localPosition = (points[0]);
point2.transform.localPosition = (points[1]);
point3.transform.localPosition = (points[2]);
point4.transform.localPosition = (points[3]);
Vector3 pointA = midPoint(point1.transform.position, point2.transform.position);
Vector3 pointB = midPoint(point3.transform.position, point4.transform.position);
Vector3 between = pointB - pointA;
float distance = between.magnitude;
squareMarker.transform.position = pointA + (between / 2.0f);
squareMarker.transform.LookAt(pointB);
worldContainer.transform.position = squareMarker.transform.position;
worldContainer.transform.rotation = squareMarker.transform.rotation;
}
private Vector3 midPoint(Vector3 a, Vector3 b)
{
float x = (a.x + b.x) / 2;
float y = (a.y + b.y) / 2;
float z = (a.z + b.z) / 2;
return new Vector3(x, y, z);
}
Thats all it takes to center the world around the player. If you have any other questions or have feedback on a way to improve this, please reach out!
06-08-2022 06:11 AM
Thanks for writing back! I'm having the exact same issue. Can you please post your code sample?
06-10-2022 05:10 AM
Hi, Did you find the solution.! if you get it then share it's snap. and I face the issue when i come after device lose focus or On device after sleep than guardian points is change in game. how tackle this issue.
06-10-2023 01:20 PM
Yes but no, since it will mess as soon as you will instantiate objects at runtime or use static objects in the scene. Is the OVR Scene only for Mixed Reality or is it usable for full VR too?
06-15-2023 08:43 AM
What is the GuardianBoundaryEnforcer you're talking about? I can't find anything related.