플레이어 따라가는 카메라 기능 구현
This commit is contained in:
Binary file not shown.
+11857
-54
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c9cfa26abfee488c85f1582747f6a02
|
||||
guid: 21b75e2a5915a42e9971c7e3fce6fd8f
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
[Header("추적 대상 설정")]
|
||||
public Transform target; // 카메라가 따라갈 대상 (Player)
|
||||
|
||||
[Header("카메라 움직임 옵션")]
|
||||
public float smoothSpeed = 0.125f; // 카메라 추적 속도 (낮을수록 부드러움)
|
||||
// 캐릭터가 화면 중앙보다 살짝 아래에 위치하여 윗시야를 넓히도록 Y 오프셋을 1.5f로 지정합니다.
|
||||
public Vector3 offset = new Vector3(0f, 1.5f, -10f);
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
// 씬에서 플레이어를 검색하여 자동으로 타겟으로 설정합니다.
|
||||
Player player = FindObjectOfType<Player>();
|
||||
if (player != null)
|
||||
{
|
||||
target = player.transform;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 카메라가 이동하고자 하는 목표 위치 (오프셋 합산)
|
||||
Vector3 desiredPosition = target.position + offset;
|
||||
|
||||
// Lerp를 사용하여 현재 위치에서 목표 위치까지 부드럽게 보간 이동
|
||||
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
|
||||
|
||||
// 카메라 위치 갱신
|
||||
transform.position = smoothedPosition;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f5826fa719de4292b2757cb205ae1d3
|
||||
Reference in New Issue
Block a user