From f0f578eddccb1bbcd60e6f22fc35f029b81cd903 Mon Sep 17 00:00:00 2001 From: KINDNICK Date: Sat, 10 May 2025 15:22:21 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B9=B4=EB=A9=94=EB=9D=BC=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=ED=8C=A8=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CameraController.cs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Streamingle/StreamingleControl/Controllers/CameraController.cs b/Assets/Scripts/Streamingle/StreamingleControl/Controllers/CameraController.cs index 987592ca..330a7f90 100644 --- a/Assets/Scripts/Streamingle/StreamingleControl/Controllers/CameraController.cs +++ b/Assets/Scripts/Streamingle/StreamingleControl/Controllers/CameraController.cs @@ -158,6 +158,8 @@ public class CameraManager : MonoBehaviour, IController private InputHandler inputHandler; private CameraPreset currentPreset; private Vector3 rotationCenter = Vector3.zero; + private float currentOrbitDistance = 0f; + private float currentOrbitHeight = 0f; private Vector3 rotationStartPosition; private bool isRotating = false; @@ -321,11 +323,15 @@ public class CameraManager : MonoBehaviour, IController { if (!isRotating) { - // 회전 시작 시 현재 위치 저장 + // 회전 시작 시 현재 상태 저장 isRotating = true; rotationStartPosition = cameraTransform.position; - // 현재 카메라의 y값을 기준으로 회전 중심점 설정 rotationCenter = new Vector3(0f, rotationStartPosition.y, 0f); + + // 현재 카메라의 회전 중심점으로부터의 거리와 높이 계산 + Vector3 toCamera = cameraTransform.position - rotationCenter; + currentOrbitDistance = new Vector3(toCamera.x, 0f, toCamera.z).magnitude; + currentOrbitHeight = toCamera.y; } Vector2 lookDelta = inputHandler.GetLookDelta(); @@ -334,26 +340,19 @@ public class CameraManager : MonoBehaviour, IController // 현재 회전값을 오일러 각도로 가져오기 Vector3 currentEuler = cameraTransform.eulerAngles; - // X축 회전값을 -80도에서 80도 사이로 제한하기 위해 360도 형식에서 변환 - float currentX = currentEuler.x; - if (currentX > 180f) currentX -= 360f; - - // 새로운 회전값 계산 - float newX = currentX - lookDelta.y * rotationSensitivity; + // Y축 회전만 적용 (수평 회전) float newY = currentEuler.y + lookDelta.x * rotationSensitivity; - // X축 회전 제한 (-80도 ~ 80도) - newX = Mathf.Clamp(newX, -80f, 80f); + // 회전 적용 (X축 회전은 0으로 고정) + Quaternion targetRotation = Quaternion.Euler(0f, newY, 0f); - // 회전 적용 - Quaternion targetRotation = Quaternion.Euler(newX, newY, 0f); + // 오비탈 회전을 위한 새로운 위치 계산 + Vector3 orbitPosition = targetRotation * Vector3.back * currentOrbitDistance; + orbitPosition.y = currentOrbitHeight; // 높이 유지 + + // 회전 중심점을 기준으로 새로운 위치 설정 + cameraTransform.position = rotationCenter + orbitPosition; cameraTransform.rotation = targetRotation; - - // 회전 시작 위치를 기준으로 회전 (y값 유지) - Vector3 relativePosition = rotationStartPosition - rotationCenter; - Vector3 rotatedPosition = targetRotation * new Vector3(relativePosition.x, 0f, relativePosition.z); - Vector3 newPosition = rotationCenter + rotatedPosition; - cameraTransform.position = newPosition; } else {