using Unity.VisualScripting;
|
using Unity.XR.CoreUtils;
|
using UnityEngine;
|
using UnityEngine.XR;
|
|
public class CameraRecenter : Singleton<CameraRecenter>
|
{
|
public Transform head;
|
public Transform origin;
|
public Transform target;
|
|
|
bool isRecenter = false;
|
|
|
|
public void RecenterCamera()
|
{
|
Vector3 offset = head.position - origin.position;
|
offset.y = 0;
|
origin.position = target.position - offset;
|
|
Vector3 targetForward = target.forward;
|
targetForward.y = 0;
|
Vector3 cameraForward = head.forward;
|
cameraForward.y = 0;
|
|
float angle = Vector3.SignedAngle(cameraForward, targetForward, Vector3.up);
|
|
origin.RotateAround(head.position, Vector3.up, angle);
|
|
}
|
|
|
//private void Update()
|
//{
|
// if (isRecenter) return;
|
// RecenterCamera();
|
// isRecenter = true;
|
//}
|
}
|