mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-04 01:49:07 +00:00
I wanna go to bed
This commit is contained in:
@@ -17,8 +17,6 @@ public class PortalManager : MonoBehaviour
|
||||
PortalManager m_OtherManager;
|
||||
PortalCamera m_PortalCamera;
|
||||
|
||||
bool m_PlayerOverlapping = false;
|
||||
|
||||
// Gets the other end of the portal
|
||||
public PortalManager Linked() => m_OtherManager;
|
||||
|
||||
@@ -44,38 +42,11 @@ public class PortalManager : MonoBehaviour
|
||||
m_PortalCamera.InitCamera(m_PortalRenderer, this, transform.parent.localEulerAngles * 2.0f);
|
||||
}
|
||||
|
||||
// Updates is called every frame
|
||||
// Updates is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Updates the player position relative to the portal
|
||||
m_PlayerPoint.position = CameraController.Instance().transform.position;
|
||||
|
||||
// Checks if the player is overlapping with the portal
|
||||
if (m_PlayerOverlapping)
|
||||
{
|
||||
// Calculates if the player is going towards the portal
|
||||
Vector3 difference = PlayerMovement.Pos() - transform.position;
|
||||
float dotProduct = Vector3.Dot(m_PortalRenderer.gameObject.transform.up, difference);
|
||||
|
||||
// If this is true the player has crossed the portal
|
||||
if (dotProduct < 0f && PlayerMovement.CanGoThroughPortals())
|
||||
{
|
||||
// Rotates the player
|
||||
float rotDif = -Quaternion.Angle(transform.rotation, m_OtherManager.transform.rotation);
|
||||
rotDif += 180.0f;
|
||||
CameraController.Instance().RotatePlayerDirection(new Vector2(0f, rotDif));
|
||||
|
||||
// Teleports the player
|
||||
Vector3 offset = Quaternion.Euler(0f, rotDif, 0f) * difference;
|
||||
PlayerMovement.SetPos(m_OtherManager.transform.position + PlayerOffset() - new Vector3(0, 2, 0));
|
||||
|
||||
// Tellss the player it went through a portal
|
||||
PlayerMovement.Instance().WentThroughPortal(rotDif);
|
||||
|
||||
// Stops the overlapping as it has ended
|
||||
m_PlayerOverlapping = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When something enters the portal
|
||||
@@ -83,15 +54,52 @@ public class PortalManager : MonoBehaviour
|
||||
{
|
||||
// Changing the state if it is not the player will causes issues
|
||||
if (other.CompareTag(PlayerMovement.Object().tag) == false) { return; }
|
||||
m_PlayerOverlapping = true;
|
||||
|
||||
// Calculates the differemce of some stuff
|
||||
Vector3 difference = PlayerMovement.Pos() - transform.position;
|
||||
|
||||
// Checks they are able to travel through portals
|
||||
if (PlayerMovement.CanGoThroughPortals())
|
||||
{
|
||||
Debug.Log("Telpeoted opaktyer");
|
||||
|
||||
// Rotates the player
|
||||
float rotDif = -Quaternion.Angle(transform.rotation, m_OtherManager.transform.rotation);
|
||||
rotDif += 180.0f;
|
||||
CameraController.Instance().RotatePlayerDirection(new Vector2(0f, rotDif));
|
||||
|
||||
// Tells 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.5f, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// When something exits the portal
|
||||
private void OnTriggerExit(Collider other)
|
||||
//
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
Debug.Log("Force teleported player");
|
||||
|
||||
// Changing the state if it is not the player will causes issues
|
||||
if (other.CompareTag(PlayerMovement.Object().tag) == false) { return; }
|
||||
m_PlayerOverlapping = false;
|
||||
|
||||
if (collision.gameObject.CompareTag(PlayerMovement.Object().tag) == false) { return; }
|
||||
|
||||
// Doesnt do any logic to check if the player wanted to use a portal it just forces them
|
||||
|
||||
// Calculates the differemce of some stuff
|
||||
Vector3 difference = PlayerMovement.Pos() - transform.position;
|
||||
|
||||
// Rotates the player
|
||||
float rotDif = -Quaternion.Angle(transform.rotation, m_OtherManager.transform.rotation);
|
||||
rotDif += 180.0f;
|
||||
CameraController.Instance().RotatePlayerDirection(new Vector2(0f, rotDif));
|
||||
|
||||
// Tells 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.5f, 0));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user