Skip to content

Commit

Permalink
Auto-recenter Cardboard view on level start
Browse files Browse the repository at this point in the history
  • Loading branch information
tyson-kubota committed Nov 19, 2017
1 parent cb0d322 commit fcf2282
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions setVRMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ function Start () {

(VRViewerComponent as MonoBehaviour).enabled = true; // type coercion required to access 'enabled'
(VRViewerComponent as GvrViewer).VRModeEnabled = true;

// Center Cardboard view post-instantiation, but before calling setParent on
// the main camera to make it the child of the 90-degree-offset prefab,
// since we want to map 'forward' in Cardboard-land to 'down' in world space:
if (!hasCentered) {
var VRViewer = GvrViewerMainObject.GetComponent.<GvrViewer>();
VRViewer.Instance.Recenter();
hasCentered = true;
}

// Re-parent camera for 90deg tilt offset (so player can look forward in VR):
cameraVRParent =
Instantiate(cameraVRParentPrefab);
Expand All @@ -88,13 +98,6 @@ function Start () {
VRUICameraVRTransform.localRotation = Quaternion.identity;
}

// center cardboard view post-instantiation:
// TODO: This recentering needs some kind of rotational offset to account for the parent head's 90-degree (we want to map 'forward' in cardboard to 'down' in world space)
// if (!hasCentered) {
// VRViewer = GvrViewerMainObject.GetComponent.<GvrViewer>();
// VRViewer.Instance.Recenter();
// hasCentered = true;
// }
} else if (VRViewerComponent) {
(VRViewerComponent as GvrViewer).VRModeEnabled = false;
}
Expand Down

0 comments on commit fcf2282

Please sign in to comment.