728x90
var moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
// 움직임이 있을 때만 이동 처리
if (moveDirection != Vector3.zero)
{
if (GameData.World.IsCameraIsometric())
{
Vector3 cameraRight = Camera.main.transform.right;
Vector3 cameraForward = Vector3.Cross(Vector3.up, cameraRight).normalized;
if (moveDirection.z != 0) // 상하 이동 방향이 반대일 때 보정
cameraForward = -cameraForward;
moveDirection = cameraRight * moveDirection.x + cameraForward * moveDirection.z;
}
// 이동 방향 설정
m_Agent.Move(moveDirection.normalized * m_MoveSpeed * Time.deltaTime);
// 이동 방향으로 회전
transform.rotation = Quaternion.LookRotation(moveDirection);
}
728x90
'프로그래밍 > Unity' 카테고리의 다른 글
유니티 Addressables 기반 Play Asset Delivery (0) | 2024.02.19 |
---|---|
Unity - 중세 배경의 에셋 (0) | 2023.05.21 |
Unity - 특정 씬에서 시작하기 (0) | 2023.05.03 |
Unity - 유용한 개발 에셋 유틸 : GPU Instancer (0) | 2023.04.28 |
Object Pool 에 들어간 class 의 동작 (0) | 2023.03.21 |
댓글