I wanna go to bed

This commit is contained in:
2025-04-04 11:46:10 +01:00
parent 653876e56e
commit 46db31b405
5 changed files with 522 additions and 496 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -25,6 +25,13 @@ public partial class PlayerMovement : MonoBehaviour
// Resets portal state
m_PortalFrameCounter = Mathf.Max(0, m_PortalFrameCounter - 1);
// Transfers all stored velocity to the player
if (m_StoredVel != Vector3.zero)
{
m_Body.velocity = m_StoredVel;
m_StoredVel = Vector3.zero;
}
// Works out the new state of the player
UpdatePlayerState();
@@ -94,11 +101,14 @@ public partial class PlayerMovement : MonoBehaviour
public void WentThroughPortal(float change)
{
// Resets the counter
m_PortalFrameCounter = 3;
m_PortalFrameCounter = 5;
// Rotates the velocity of the player
Vector3 vel = m_Body.velocity;
vel = Quaternion.AngleAxis(change, Vector3.up) * vel;
m_Body.velocity = vel;
// Stores the velocity
m_StoredVel = vel;
}
}

View File

@@ -85,12 +85,20 @@ public partial class PlayerMovement : MonoBehaviour
//
int m_PortalFrameCounter = 0;
//
Vector3 m_StoredVel;
// Only instance of the player
static PlayerMovement s_Instance;
public static Transform Orientation() => s_Instance.m_Orientation;
public static Vector3 Pos() => s_Instance.transform.position;
public static void SetPos(Vector3 v) => s_Instance.transform.parent.position = v;
public static void SetPos(Vector3 v)
{
//Debug.Log(v);
s_Instance.transform.parent.position = v;
}
public static GameObject Object() => s_Instance.gameObject;
public static bool CanGoThroughPortals() => s_Instance.m_PortalFrameCounter == 0;
public static PlayerMovement Instance() => s_Instance;

View File

@@ -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));
}
}

View File

@@ -10,7 +10,7 @@ Shader "Unlit/ScreenCutoutShader"
{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Lighting Off
Cull Back
Cull Off
ZWrite On
ZTest Less