Facebook
From Maciej, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 54
  1.     public Transform playerCamera;
  2.     public Transform portal;
  3.     public Transform otherPortal;
  4.     float myAngle;
  5.     // Start is called before the first frame update
  6.     void Start()
  7.     {
  8.        
  9.     }
  10.  
  11.     // Update is called once per frame
  12.     void Update()
  13.     {
  14.         Vector3 playerOffsetFromPortal = playerCamera.position - otherPortal.position;
  15.         transform.position = portal.position + playerOffsetFromPortal;
  16.         float angularDifferenceBetweenPortalRotations = Quaternion.Angle(portal.rotation,otherPortal.rotation);
  17.         if (myAngle == 90 || myAngle == 270)
  18.         {
  19.             angularDifferenceBetweenPortalRotations -= 90;
  20.         }
  21.         Quaternion portalRotationalDifference =
  22.         Quaternion.AngleAxis(angularDifferenceBetweenPortalRotations, Vector3.up);
  23.         Vector3 newCameraDirection = portalRotationalDifference * playerCamera.forward;
  24.         if (myAngle == 90 || myAngle == 270)
  25.         {
  26.             newCameraDirection = new Vector3(newCameraDirection.z * -1, newCameraDirection.y,
  27.             newCameraDirection.x);
  28.             transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
  29.         }
  30.         else
  31.         {
  32.             newCameraDirection = new Vector3(newCameraDirection.x * -1, newCameraDirection.y,
  33.             newCameraDirection.z * -1);
  34.             transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
  35.         }
  36.     }