Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PortalCamera : MonoBehaviour
- {
- public Transform playerCamera;
- public Transform portal;
- public Transform otherPortal;
- private float myAngle;
- private void Update()
- {
- PortalCameraController();
- }
- private void PortalCameraController()
- {
- Vector3 playerOffsetFromPortal = playerCamera.position - otherPortal.position;
- float angularDiff = Quaternion.Angle(portal.rotation, otherPortal.rotation);
- if (myAngle == 90 || myAngle == 270)
- {
- angularDiff -= 90;
- }
- Quaternion portalRotationDiff = Quaternion.AngleAxis(angularDiff, Vector3.up);
- Vector3 newCameraDirection = portalRotationDiff * playerCamera.forward;
- if (myAngle == 90 || myAngle == 270)
- {
- newCameraDirection = new Vector3(newCameraDirection.z * -1, newCameraDirection.y,
- newCameraDirection.x);
- }
- else
- {
- newCameraDirection = new Vector3(newCameraDirection.x * -1, newCameraDirection.y,
- newCameraDirection.z * -1);
- }
- transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
- }
- public void SetMyAngle(float angle)
- {
- myAngle = angle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement