본문 바로가기
유니티

유니티 목표지점으로 이동하기

by 실버dev 2019. 11. 2.

1. MoveTowards

Vector3 target = new Vector3(-4f, 1.5f, 0);
void Update()
{
	transform.position = Vector3.MoveTowards(transform.position, target, 0.1f);
}

transform.position은 현재 위치를 나타낸다.

Vector3.MoveTowards(현재위치, 목표위치, 속도);

 

 

 

2. SmoothDamp

Vector3 target = new Vector3(-4f, 1.5f, 0);
void Update()
{
	Vector3 velo = Vector3.zero;
	transform.position = Vector3.SmoothDamp(transform.position, target, ref velo, 0.1f);
}

부드럽게 이동한다.

velo는 다른 속도값을 참조할수 있는것이다.

(Vector3.up을 적용하면 위로 올라감.)

속도 값은 반비례한다.

 

 

 

 

3. Lerp(선형보간)

Vector3 target = new Vector3(-4f, 1.5f, 0);
void Update()
{
	Vector3 velo = Vector3.zero;
	transform.position = Vector3.Lerp(transform.position, target, 0.1f);
}

SmoothDamp보다 감속시간이 길다

 

 

 

 

4. Slerp(구면 선형보간)

 

Vector3 target = new Vector3(-4f, 1.5f, 0);
void Update()
{
	Vector3 velo = Vector3.zero;
	transform.position = Vector3.Slerp(transform.position, target, 0.1f);
}

포물선을 그리며 이동한다.

 

 

'유니티' 카테고리의 다른 글

유니티 rigidbody  (0) 2019.11.07
유니티 오브젝트 충돌 관련 컴포넌트  (1) 2019.11.03
유니티 키입력, 이동  (0) 2019.11.02
유니티 라이프 사이클  (0) 2019.11.02
유니티용 C# 문법  (0) 2019.11.02