Unity(6)
Unity(6) Camera
Camera의 구성 요소:
- Background: 스카이박스가 없을 시, 여백의 색
- Culling Mask: 카메라에 보이게 할 Layer 설정
- Projection: 원근감 선택하기
- Perspective: 현실의 원근감과 비슷하다.
- Orthographic: 원근감 없이 보이게 하는 방식.
- Field of view: 카메라의 시야각, 클수록 넓게 보인다.
- Clipping Planes: 랜더링을 수행할 최소 거리와 최장 거리 설정
- Depth: 랜더링 순서의 카메라 포지션, 값이 큰 카메라는 작은 카메라 위에 랜더링 됨
- Target Display: 담당할 디스플레이 번호를 의미
Player를 따라가는 카메라 만들기.
현재 까지의 과정으로는 고정된 카메라로 물체의 움직을 봐야한다.
카메라를 벗어났을 시 어디에 있는지 알 수 없다.
방법 1.
Hierarcy 창에서 main camera를 player에 drag drop 해본다.
-> 카메라가 player를 따라서 움직임, 하지만 camera의 좌표가 player의 좌표계에 종속되, 빙글 빙글 돈다.
다시 원래의 상태로 돌려 놓고, 카메라가 회전하지 않도록 해보자.
방법 2.
- 카메라가 회전하지 않게, CameraMovement 스크립트 생성한다.
- 아래의 코드를 작성해준다.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public Transform playerTransform;//플레이어의 위치
private Vector3 offset; //플레이어와 카메라의 거리리
// Start is called before the first frame update
void Awake()
{
offset = transform.position - playerTransform.position;// offset 설정정
}
// Update is called once per frame
void Update()
{
transform.position = playerTransform.position + offset;
}
}
다시 실행 시켜보면 카메라가 player를 잘 따라다니는 것을 볼 수 있다.
감사합니다.
This post is licensed under CC BY 4.0 by the author.