-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortalCamera.cs
More file actions
23 lines (18 loc) · 884 Bytes
/
Copy pathPortalCamera.cs
File metadata and controls
23 lines (18 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PortalCamera : MonoBehaviour {
public Transform playerCamera;
public Transform portal;
public Transform otherPortal;
// Update is called once per frame
void Update ()
{
Vector3 playerOffsetFromPortal = playerCamera.position - otherPortal.position;
transform.position = portal.position + playerOffsetFromPortal;
float angularDifferenceBetweenPortalRotations = Quaternion.Angle(portal.rotation, otherPortal.rotation);
Quaternion portalRotationalDifference = Quaternion.AngleAxis(angularDifferenceBetweenPortalRotations, Vector3.up);
Vector3 newCameraDirection = portalRotationalDifference * playerCamera.forward;
transform.rotation = Quaternion.LookRotation(newCameraDirection, Vector3.up);
}
}