Priv's Blog
벡터를 사용해 게임 오브젝트 사이의 거리 계산하는 방법 3가지 본문
출처
오브젝트간 거리 체크 / Vector3.Distance, magnitude, sqrMagnitude
유니티 버전 2017.2 오브젝트간의 transform position 거리를 체크하고 싶을 때, 세 가지 방법이 있다. 1) ...
blog.naver.com
1. Vector3.Distance
2번 항목에서 설명할 Vector3.magnitude와 성능과 사용 방법은 동일하다.
정확한 거리를 계산해 반환하지만, Vector3.sqrMagnitude보다는 속도가 느리다.
참고
Unity - Scripting API: Vector3.Distance
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
2. Vector3.magnitude
1번 항목인 Vector3.Distance와 성능과 기능은 동일하다.
3축 사이의 정확한 거리를 계산해 Vector3 타입으로 반환한다.
출처
Unity - Scripting API: Vector3.magnitude
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
3. Vector3.sqrMagnitude
1번, 2번 항목과 다르게 제곱 값을 루트 계산 없이 그대로 반환한다.
정확한 거리는 측정할 수 없으므로, 두 벡터 사이에 무엇이 더 크고 작은 지 판단하기 위한 용도로 사용하기에 적합하다.
참고
Unity - Scripting API: Vector3.sqrMagnitude
The magnitude of a vector v is calculated as Mathf.Sqrt(Vector3.Dot(v, v)). However, the Sqrt calculation is quite complicated and takes longer to execute than the normal arithmetic operations. Calculating the squared magnitude instead of using the magnitu
docs.unity3d.com
'Dev. Study Note > Unity' 카테고리의 다른 글
유니티 에디터 상에서 public처럼 private 변수 값에 접근하는 법 (0) | 2021.07.10 |
---|---|
UGUI 세팅 (0) | 2021.06.26 |
유니티 5에서 Scene을 불러올 때 라이트 설정이 틀어질 경우 (0) | 2021.03.22 |
카메라를 자식 오브젝트로 만들어 기준점을 중심으로 시야 회전시키기 (0) | 2021.03.06 |
Awake()와 Start() (0) | 2021.02.27 |