This commit is contained in:
2025-05-02 14:57:55 +01:00
parent c191af0d4b
commit b2530ee2b7
9 changed files with 849 additions and 577 deletions

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PortalBack : MonoBehaviour
{
[SerializeField] PortalManager m_Manager;
// private void OnCollisionEnter(Collision collision) => m_Manager.ForceTeleport();
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 859e4c4c9b11c654a8ab3891fbd8c5b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -18,7 +18,7 @@ public class PortalManager : MonoBehaviour
// Private variables //
PortalManager m_OtherManager;
PortalCamera m_PortalCamera;
[SerializeField] PortalCamera m_PortalCamera;
// Gets the other end of the portal
public PortalManager Linked() => m_OtherManager;
@@ -52,6 +52,23 @@ public class PortalManager : MonoBehaviour
m_PlayerPoint.position = CameraController.Instance().transform.position;
}
public void ForceTeleport()
{
// Calculates if the player is going towards the portal
Vector3 difference = PlayerMovement.Pos() - transform.position;
// Rotates the player
float rotDif = -Quaternion.Angle(transform.rotation, m_OtherManager.transform.rotation) + m_AngleDif;
CameraController.Instance().RotatePlayerDirection(new Vector2(0f, rotDif));
// Tellss the player it went through a portal
PlayerMovement.Instance().WentThroughPortal(rotDif);
// Teleports the player
Vector3 offset = Quaternion.Euler(0f, rotDif, 0f) * difference;
PlayerMovement.SetPos(m_OtherManager.transform.position + offset - new Vector3(0, 1.0f, 0));
}
// When something enters the portal
private void OnTriggerEnter(Collider other)
{