private void updateUiPanelScaleAndPosition() { var offsetPosition = new Vector3(0f, VHVRConfig.GetUiPanelVerticalOffset(), VHVRConfig.GetUiPanelDistance()); if (useDynamicallyPositionedGui()) { var playerInstance = Player.m_localPlayer; var currentDirection = getCurrentGuiDirection(); if (isRecentering) { // We are currently recentering, so calculate a new rotation a step towards the targe rotation // and set the GUI position using that rotation. If the new rotation is close enough to // the target rotation, then stop recentering for the next frame. var targetDirection = getTargetGuiDirection(); var stepDirection = Vector3.Slerp(currentDirection, targetDirection, VHVRConfig.GuiRecenterSpeed() * Mathf.Deg2Rad * Time.deltaTime); var stepRotation = Quaternion.LookRotation(stepDirection, VRPlayer.instance.transform.up); _uiPanel.transform.rotation = stepRotation; _uiPanel.transform.position = playerInstance.transform.position + stepRotation * offsetPosition; lastVrPlayerRotation = VRPlayer.instance.transform.rotation; maybeResetIsRecentering(stepDirection, targetDirection); } else { // We are not recentering, so keep the GUI in front of the player. Need to account for // any rotation of the VRPlayer instance caused by mouse or joystick input since the last frame. float rotationDelta = VRPlayer.instance.transform.rotation.eulerAngles.y - lastVrPlayerRotation.eulerAngles.y; lastVrPlayerRotation = VRPlayer.instance.transform.rotation; var newRotation = Quaternion.LookRotation(currentDirection, VRPlayer.instance.transform.up); newRotation *= Quaternion.AngleAxis(rotationDelta, Vector3.up); _uiPanel.transform.rotation = newRotation; _uiPanel.transform.position = playerInstance.transform.position + newRotation * offsetPosition; } } else { _uiPanel.transform.rotation = VRPlayer.instance.transform.rotation; _uiPanel.transform.position = VRPlayer.instance.transform.position + VRPlayer.instance.transform.rotation * offsetPosition; } float ratio = (float)Screen.width / (float)Screen.height; _uiPanel.transform.localScale = new Vector3(VHVRConfig.GetUiPanelSize() * ratio, VHVRConfig.GetUiPanelSize(), 1f); }