본문 바로가기

Unity/Unity3D

Unity- 목표지점으로 이동

Vector3 class안의 여러 함수들을 살펴보자

 

*참조

Vector3.zero : Vector3(0, 0, 0)인 벡터

Vector3.one : Vector3(1, 1, 1)인 벡터

Vector3.back : Vector3(0, 0, -1)인 벡터

Vector3.down : Vector3(0, -1, 0)인 벡터

Vector3.forward : Vector3(0, 0, 1)인 벡터

Vector3.left : Vector3(-1, 0, 0)인 벡터

Vector3.right : Vector3(1, 0, 0)인 벡터

Vector3.up : Vector3(0, 1, 0)인 벡터

 

//Unity3D API문서 

docs.unity3d.com/ScriptReference/

 

Unity - Scripting API:

Welcome to the Unity Scripting Reference! This section of the documentation contains details of the scripting API that Unity provides. To use this information, you should be familiar with the basic theory and practice of scripting in Unity which is explain

docs.unity3d.com

docs.unity3d.com/kr/530/ScriptReference/ForceMode.html

 

Unity - 스크립팅 API: ForceMode

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. 닫기

docs.unity3d.com

1. Transform.position

- Transform.position 게임오브젝트의 절대좌표를 나타냄, Transform.position Vector3를 대입하면

해당 위치로 이동

예제 : transform.position = new Vector3(x, y, z);



2. Vector3.MoveTowards

Vector3.MoveTowards는 현재 위치에서 목표 위치로 일정한 속도로 이동하는 함수입니다. 현재 위치, 목표 위치, 속도를 인자로 넘겨주고 Transform.position에 대입

 

예제 : transform.position = Vector3.MoveTowards(transform.position:Vector3, Target.position:Vector3, Speed:float);


 

 

 

3. Vector3.SmoothDamp

-시간이 지남에 따라 원하는 목표를 향해 점차적으로 벡터를 변경합니다. 가장 일반적인 용도는 팔로우 카메라를 부드럽게하는 것.

 

예제 :  transform.position =Vector3.SmoothDamp((Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime,)

*smoothTime값이 낮을 수록 빠른 속도로 이동


 

 

4. Vector3.Lerp(선형보간) and Vector.Slerp(구형 선형보간)

-(Lerp)두 점 사이를 선형 보간한다. 보간체 t에 의해 a점과 b점 사이를 보간한다. 매개변수 t는 [0, 1] 범위로 클램핑된다. 이것은 가장 일반적으로 두 끝점 사이의 선을 따라 점의 일부분을 찾는 데 사용된다(예를 들어, 그 점들 사이에서 물체를 점진적으로 이동시키는 것).

 

-(Slerp)구형으로 두 벡터 사이에 보간됩니다. a와 b 사이의 양 t. 이것과 선형 보간(일명 "lerp")의 차이점은 벡터가 공간의 점보다는 방향으로 취급된다는 것이다. 반환된 벡터의 방향은 각도에 의해 보간되고 그 크기는 부터 까지의 크기 사이에 보간된다.

 

예제 :  transform.position = Vector3.Lerp(Vector3 a, Vector3 b, float t);

*t 값은 0~1 사이 높을수록 속도 빠름

 

'Unity > Unity3D' 카테고리의 다른 글

Unity - 물체 만들기  (0) 2020.10.23
Unity - 델타타임  (0) 2020.10.23
Unity - Input과 object 이동  (0) 2020.10.19
Unity - life cycle(생명주기)  (0) 2020.10.19
Unity- C#  (0) 2020.10.15