From b9e55dd79c1679c0fde5e6876b42764a0b88078e Mon Sep 17 00:00:00 2001 From: Pasha Bibko Date: Wed, 2 Apr 2025 09:34:18 +0100 Subject: [PATCH] I THINK IT FINALLY WORKS --- Assets/Scripts/GravityController.cs | 3 +-- Assets/Scripts/Portals/PortalCamera.cs | 8 +++++--- Assets/Scripts/Portals/PortalManager.cs | 16 +--------------- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/GravityController.cs b/Assets/Scripts/GravityController.cs index ab9ed72..ac34d86 100644 --- a/Assets/Scripts/GravityController.cs +++ b/Assets/Scripts/GravityController.cs @@ -9,8 +9,7 @@ public class GravityController const float m_GravityScale = -20.0f; // Private constructor to stop accidental creation - private GravityController() - { } + private GravityController() { } public static GravityController Instance() { diff --git a/Assets/Scripts/Portals/PortalCamera.cs b/Assets/Scripts/Portals/PortalCamera.cs index 846b237..3c6cf11 100644 --- a/Assets/Scripts/Portals/PortalCamera.cs +++ b/Assets/Scripts/Portals/PortalCamera.cs @@ -43,9 +43,11 @@ public class PortalCamera : MonoBehaviour // Update is called every frame void Update() { - Vector3 offset = m_CapturePortal.PlayerOffset(); - transform.parent.position = offset; + // Gets the offset of the player from the display portal + Vector3 offset = m_DisplayPortal.PlayerOffset(); - transform.parent.position = m_CapturePortal.TranslateOffsetToSpace(m_DisplayPortal.PlayerOffset(), Vector3.zero); + // Translates it to the capture portal and assigns it to the camera position + Transform t = m_CapturePortal.transform.parent; + transform.parent.position = (t.position) + (-t.forward * offset.z) + (t.up * offset.y) + (-t.right * offset.x); } } diff --git a/Assets/Scripts/Portals/PortalManager.cs b/Assets/Scripts/Portals/PortalManager.cs index 64ff987..441e1e8 100644 --- a/Assets/Scripts/Portals/PortalManager.cs +++ b/Assets/Scripts/Portals/PortalManager.cs @@ -18,13 +18,7 @@ public class PortalManager : MonoBehaviour PortalCamera m_PortalCamera; public PortalManager Linked() => m_OtherManager; - - public Vector3 pos => transform.parent.position; - public Quaternion rot => transform.parent.rotation; - - public void SetPos(Vector3 v) => transform.parent.position = v; - - public Vector3 PlayerOffset() => m_PlayerPoint.position; + public Vector3 PlayerOffset() => m_PlayerPoint.localPosition; // Start is called before the first frame update void Start() @@ -50,12 +44,4 @@ public class PortalManager : MonoBehaviour { m_PlayerPoint.position = CameraController.Instance().transform.position; } - - public Vector3 TranslateOffsetToSpace(Vector3 pos, Vector3 euler) - { - m_Rot.localEulerAngles = euler; - m_Pos.localPosition = pos; - - return m_Pos.position; - } }