using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private float camTargetRotation = 0;
private bool isCamRotating = false;
public Transform playerCamHome;
private void Update()
{
HandleCamRotation();
}
///
/// Trigger cam rotation
///
public void RotateCam()
{
if (!isCamRotating)
{
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
camTargetRotation = currentY + 90f;
isCamRotating = true;
}
}
///
/// Move cam to desired rotation (every frame)
///
void HandleCamRotation()
{
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
float step = 200 * Time.deltaTime;
float newY = Mathf.MoveTowardsAngle(currentY, camTargetRotation, step);
playerCamHome.RotateAround(
transform.position,
Vector3.up,
newY - currentY
);
if (Mathf.Abs(Mathf.DeltaAngle(newY, camTargetRotation)) < 0.01f)
{
isCamRotating = false;
}
}
}