카메라 움직임 수정

카메라가 target(플레이어)을 더 부드럽게 따라감

플레이어의 대각선 이동 속도 수정

기존: 대각선으로 이동 시 플레이어의 속도가 1.5배 정도 더 빠름

수정: Animator의 Blend Tree를 조정해 모든 방향의 속도를 표준화한다

이어서 할것들

CameraController 스크립트에서 카메라 움직임 코드가 Update() 함수에 들어있어 한 프레임 기준으로 카메라의 움직임이 조정된다 (update() 함수는 한 프레임 당 한 번 호출)

LateUpdate() 함수 사용

카메라의 움직임이 좀 더 부드러워짐

CameraController 스크립트

public class CameraController : MonoBehaviour
{
    public Transform target;
    public float smoothing;

    void Start()
    {
        
    }

    void LateUpdate()
    {
        // transform.position = new Vector3(target.transform.position.x, target.transform.position.y, transform.position.z);

        Vector3 targetPosition = new Vector3(target.position.x, target.position.y, transform.position.z);

        // 플레이어와 카메라의 position이 다른 경우
				if (transform.position != target.position)
        {
            transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing);
        }
    }
}

Smoothing: 0.1

스크린샷 2023-08-08 132918.png

벡터의 정규화(normalized)

오브젝트의 균일한 이동을 위하여 벡터의 정규화가 필요함

모든 방향의 벡터 길이가 1 이어야 방향에 따른 이동 속도가 같아지기 때문