카메라를 player를 향해 부드럽게 따라가는 소스를 만들어보자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class follow : MonoBehaviour { public Transform target; // target public float dist = 10.0f; // 거리 public float height = 5.0f; // 높이 public float dampRotate = 5.0f; //회전 속도 private Transform tr; // 카메라 private void Start() { tr = GetComponent(); } void LateUpdate() { float cur_Y_Angle = Mathf.LerpAngle(tr.eulerAngles.y, target.eulerAngles.y, dampRotate * Time.deltaTime); //Mathf.LerpAngle(float s, float e, flaot t) = t시간 동안 s부터 e까지 각도를 변환하는 것. Quaternion rot = Quaternion.Euler(0, cur_Y_Angle, 0); tr.position = target.position - (rot * Vector3.forward * dist) + (Vector3.up * height); //타겟 위치 - 카메라위치 = 카메라가 타겟 뒤로 가야 타겟이 보이겠죠? tr.LookAt(target); } } |
'시바 | Unity(유니티) 5.x' 카테고리의 다른 글
Unity getkey 이벤트 차이점 (0) | 2018.03.14 |
---|---|
Unity2D 캐릭터 이동 + 점프 (0) | 2018.03.12 |
[Unity] Vector3에 대한 이해 (0) | 2018.03.09 |
[Unity] Mathf.clamp함수란? (0) | 2018.03.09 |
(Unity) 유니티 프로젝트 폴더구조 (0) | 2018.03.06 |
(Unity) 유니티 캐릭터 이동 +회전 만들기 (0) | 2018.03.05 |
(Unity) 유니티 이동, 크기, 회전 변경 코드 정리 (0) | 2018.03.05 |
(Unity) 유니티 다운로드 설치 (0) | 2018.03.05 |