백지부터 시작하는 이세계 코딩 생활
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.
유니티3D, 게임 오브젝트를 특정 대상을 바라보게 하기
방법1) Quaternion.LookRotation 1 2 3 4 5 6 7 public Transform target; void Update() { Vector3 vec = target.position - transform.position; vec.Normalize(); Quaternion..
legacy.tistory.com
[유니티] Quaternion.LookRotation
public static Quaternion Quaternion.LookRotation(Vector3 forward); public static Quaternion Q...
blog.naver.com
docs.unity3d.com/kr/530/ScriptReference/Vector3.Normalize.html
Unity - 스크립팅 API: Vector3.Normalize
벡터가 정규화(normalized)되면, 벡터는 갖은 방향값을 갖지만, 정규화 벡터의 길이는 1.0입니다. 이 함수는 현재 벡터를 변경한다는 점을 주의하십시오. 현재 벡터가 변경되지 않도록 하고 싶은 경
docs.unity3d.com
방향 벡터 - 벡터의 정규화(normalized) 유니티
더보기 "유니티 방향 벡터" "유니티 노말라이즈드" 오브젝트 균일한 이동을 위하여 벡터의 정규화가 필요합니다. 그 이유는 모든 방향의 벡터 길이가 1 이어야 방향에 따른 이동 속도가 같아지기
seojingames.tistory.com
'백지부터 시작하는 이세계 유니티 생활 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 |