백지부터 시작하는 이세계 코딩 생활
Quaternion, LookRotation, Normalize 본문
Quaternion . LookRotation(Vector3)
해당 Object가 Vector3 방향으로 향하게끔 해준다.
특정 방향을 쳐다보게 해줌으로써 Object (ie. Player) 의 시선처리를 처리한다.
이때, Vector 값은 target과 현재 위치의 상대위치값 을 할당해야 한다.
Normalize
Vector 값의 정규화를 목적으로 사용한다. => Object의 균일한 이동을 위해 사용한다.
정규화가 되면 모든 방향으로 1 만큼씩 Vector 값이 변하게 된다.
대각선 방향의 이동이 있을 때 균일하게 움직일 수 있다.
정규화 처리가 되어있지 않은 경우, 대각선 방향으로 이동할 때 1 이상의 값을 가지고 이동하게 된다. ( 더 많이 이동 )
Quaternion
Transform의 rotation에는 Vector 좌표를 직접 입력할 수 없다.
따라서 이를 가능하도록 변환해주어야 하는데, 이 역할을 Quaternion 키워드가 처리해 준다.
( 유니티는 내부적으로 회전을 쿼터니언(Quaternion)으로 저장합니다. )
private void Rotation(Vector3 _lookDirection)
{
if (_lookDirection != Vector3.zero)
rb.MoveRotation(Quaternion.LookRotation(_lookDirection));
}
// Most of the time you can use:
// transform.LookAt instead
var target : Transform;
function Update () {
var relativePos = target.position - transform.position;
var rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
Ref.
docs.unity3d.com/kr/530/ScriptReference/Vector3.Normalize.html
'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글
Mathf, Radian, Degree, Lerp (0) | 2020.11.18 |
---|---|
MovePosition (0) | 2020.11.18 |
Rotation, Rotate (0) | 2020.11.18 |
GetComponentInChildren, GetComponentsInChildren (0) | 2020.11.18 |
Awake -- Script 및 함수들 작동 우선순위 (0) | 2020.11.18 |
Comments