백지부터 시작하는 이세계 코딩 생활

MoveTowards 본문

백지부터 시작하는 이세계 유니티 생활 since 2020

MoveTowards

조아덕 2020. 12. 24. 17:10
MoveTowards

서로 다른 위치의 놓여있는 Object들의 위치를 계산하여
특정 Object가 목표지점까지 이동할 수 있게 해주는 Vector의 내장 함수

Vector2 target = new Vector2(player.position.x, rb.position.y);
Vector2 newPos = Vector2.MoveTowards(rb.position, target, speed * Time.fixedDeltaTime);
rb.MovePosition(newPos);

 

예시 )

public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);

 

 


Ref.

1 docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html

 

Unity - Scripting API: Vector3.MoveTowards

Use the MoveTowards member to move an object at the current position toward the target position. By updating an object’s position each frame using the position calculated by this function, you can move it towards the target smoothly. Control the speed of

docs.unity3d.com

2 jsman.tistory.com/8

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

 

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

1. MoveTowards Vector3 target = new Vector3(-4f, 1.5f, 0); void Update() { transform.position = Vector3.MoveTowards(transform.position, target, 0.1f); } transform.position은 현재 위치를 나타낸다. Ve..

jsman.tistory.com

3 ssabi.tistory.com/23

Object를 이동시키는 여러가지 함수들

 

[Unity3D] 트랜스폼(Transform) 이동(Move)

유니티 좌표계 프로그램마다 사용하는 좌표계가 다릅니다. 따라서 좌표계에 대해서 이해하는 것은 매우 중요합니다. 유니티에서는 위치를 표현할 때 왼손 좌표계를 이용합니다. X축은 빨간색, Y

ssabi.tistory.com

 

Comments