From 04254f149849aaaf1cab6fd89e9606bea8db0605 Mon Sep 17 00:00:00 2001 From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com> Date: Fri, 4 Aug 2023 17:23:25 +0200 Subject: [PATCH] Fix out of bounds camera in the player's room map --- MainGameVR/Camera/VRCameraMover.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/MainGameVR/Camera/VRCameraMover.cs b/MainGameVR/Camera/VRCameraMover.cs index a14878c..a314498 100644 --- a/MainGameVR/Camera/VRCameraMover.cs +++ b/MainGameVR/Camera/VRCameraMover.cs @@ -49,9 +49,14 @@ public void MoveTo(Vector3 position, Quaternion rotation, bool keepHeight, bool } if (!quiet) { +#if DEBUG + VRLog.Debug("Moving camera to pos={0} rot={1} Trace:\n{2}", position, rotation.eulerAngles, new StackTrace(1)); +#else VRLog.Debug("Moving camera to pos={0} rot={1}", position, rotation.eulerAngles); +#endif } + _lastPosition = position; _lastRotation = rotation; @@ -84,6 +89,8 @@ public void MaybeMoveADV(ADV.TextScenario textScenario, Vector3 position, Quater var closerPosition = AdjustAdvPosition(textScenario, position, rotation); + AdjustBasedOnMap(ref closerPosition, ref rotation); + MoveWithHeuristics(closerPosition, rotation, keepHeight, !advFade.IsEnd); } @@ -167,11 +174,30 @@ public void HandleTextScenarioProgress(ADV.TextScenario textScenario) { var target = ActionCameraControl.GetIdealTransformFor(textScenario.AdvCamera); var targetPosition = target.position; + var targetRotation = target.rotation; targetPosition = AdjustAdvPosition(textScenario, targetPosition, target.rotation); + AdjustBasedOnMap(ref targetPosition, ref targetRotation); + if (ActionCameraControl.HeadIsAwayFromPosition(targetPosition)) - MoveWithHeuristics(targetPosition, target.rotation, false, isFadingOut); + MoveWithHeuristics(targetPosition, targetRotation, false, isFadingOut); + } + } + + private static void AdjustBasedOnMap(ref Vector3 targetPosition, ref Quaternion targetRotation) + { + var insideMyRoom = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == "GasyukuMyroom"; + if (insideMyRoom) + { + var middleOfRoom = new Vector3(1.3f, 1.6f, 1.2f); + + if (Vector3.Distance(targetPosition, middleOfRoom) > 10) + { + targetPosition = middleOfRoom; + var middleOfRoomRotation = Quaternion.Euler(0, 180, 0); + targetRotation = middleOfRoomRotation; + } } }