본문 바로가기
[ Unity ]/- 유니티 실습

유니티 3D 카메라 3인칭, 1인칭 Player 이동 Mode

by MRG 2024. 9. 21.
728x90
반응형

 

 

▣ 핵심 함수 설명:
Start 함수
게임 시작 시 호출되는 함수로, 초기 설정을 담당합니다.
Cursor.lockState로 마우스 커서를 화면 안에 고정하고, 카메라의 기본 거리와 시야각을 설정합니다.
카메라의 초기 위치를 업데이트하기 위해 UpdateCameraPosition을 호출합니다.


Update 함수
매 프레임마다 호출되어 사용자의 입력을 처리합니다.
마우스 움직임에 따른 카메라 회전, 1인칭/3인칭 모드 전환, 점프, 카메라 줌(마우스 우클릭) 등을 제어합니다.
우클릭을 통해 카메라 확대/축소를 처리하고, 이를 위해 각각의 코루틴(ZoomFieldOfView 및 ZoomCamera)을 실행합니다.


SetTargetDistance 함수
3인칭 모드에서 카메라의 목표 거리를 설정하는 함수입니다.
줌을 할 때 카메라가 어느 정도까지 가까워지거나 멀어질지를 설정합니다.


SetTargetFoV 함수
1인칭 모드에서 카메라의 목표 시야각(Field of View)을 설정하는 함수입니다.
줌 시 시야각을 좁히거나 넓히는 작업을 담당합니다.


FirstPersonMovement 함수
1인칭 모드에서 플레이어의 이동과 카메라의 회전을 처리합니다.
플레이어가 W, A, S, D 키로 이동할 때 카메라가 플레이어의 머리 위치에 고정됩니다. 마우스 움직임에 따라 카메라가 회전하도록 처리합니다.


ThirdPersonMovement 함수
3인칭 모드에서 플레이어의 이동을 처리합니다.
플레이어의 이동과 함께 카메라가 플레이어를 일정한 거리에서 따라가도록 구현됩니다.


UpdateCameraPosition 함수
카메라의 위치와 회전을 업데이트합니다.
카메라가 플레이어의 위치를 중심으로 일정한 거리를 유지하면서 플레이어를 바라보도록 설정합니다.
3인칭 모드에서 카메라가 플레이어 주위를 회전하는지 또는 고정된 위치에서 바라보는지를 제어합니다.


ZoomCamera 코루틴
3인칭 모드에서 카메라의 거리를 부드럽게 조정합니다.
현재 거리와 목표 거리를 Mathf.Lerp로 보간하여 부드럽게 카메라가 이동하도록 구현됩니다.


ZoomFieldOfView 코루틴
1인칭 모드에서 카메라의 시야각(Field of View)을 부드럽게 조정합니다.
현재 시야각과 목표 시야각을 Mathf.Lerp로 보간하여 자연스럽게 확대/축소를 구현합니다.

 

https://docs.unity3d.com/ScriptReference/Cursor-lockState.html

 

Unity - Scripting API: Cursor.lockState

Description Determines whether the hardware pointer is locked to the center of the view, constrained to the window, or not constrained at all. A locked cursor is positioned in the center of the view and cannot be moved. The cursor is invisible in this stat

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/Camera-fieldOfView.html

 

Unity - Scripting API: Camera.fieldOfView

This is the vertical field of view; horizontal field of view depends on the viewport's aspect ratio. For for more information, see VerticalToHorizontalFieldOfView. If Camera.orthographic is true, the Camera ignores fieldOfView. Some VR SDKs have fixed fiel

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/Input.GetAxis.html

 

Unity - Scripting API: Input.GetAxis

The value will be in the range -1...1 for keyboard and joystick input devices. The meaning of this value depends on the type of input control, for example with a joystick's horizontal axis a value of 1 means the stick is pushed all the way to the right and

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/CharacterController.Move.html

 

Unity - Scripting API: CharacterController.Move

The CharacterController.Move motion moves the GameObject in the given direction. The given direction requires absolute movement delta values. A collision constrains the Move from taking place. The return, CollisionFlags, indicates the direction of a collis

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/Transform.LookAt.html

 

Unity - Scripting API: Transform.LookAt

Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis. The up vector of the rotation will only match the worldUp vecto

docs.unity3d.com

 

728x90
반응형

댓글