Advertisement
drakon-firestone

PortalCamera

Apr 19th, 2023
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PortalCamera : MonoBehaviour
  6. {
  7. public Transform playerCamera;
  8. public Transform portal;
  9. public Transform otherPortal;
  10.  
  11. private float myAngle;
  12.  
  13. private void Update()
  14. {
  15. PortalCameraController();
  16. }
  17.  
  18. private void PortalCameraController()
  19. {
  20. Vector3 playerOffsetFromPortal = playerCamera.position - otherPortal.position;
  21.  
  22. float angularDiff = Quaternion.Angle(portal.rotation, otherPortal.rotation);
  23.  
  24. if (myAngle == 90 || myAngle == 270)
  25. {
  26. angularDiff -= 90;
  27. }
  28.  
  29. Quaternion portalRotationDiff = Quaternion.AngleAxis(angularDiff, Vector3.up);
  30. Vector3 newCameraDirection = portalRotationDiff * playerCamera.forward;
  31.  
  32. if (myAngle == 90 || myAngle == 270)
  33. {
  34. newCameraDirection = new Vector3(newCameraDirection.z * -1, newCameraDirection.y,
  35. newCameraDirection.x);
  36. }
  37. else
  38. {
  39. newCameraDirection = new Vector3(newCameraDirection.x * -1, newCameraDirection.y,
  40. newCameraDirection.z * -1);
  41. }
  42.  
  43. transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
  44. }
  45.  
  46. public void SetMyAngle(float angle)
  47. {
  48. myAngle = angle;
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement