백지부터 시작하는 이세계 코딩 생활
MoveTowards 본문
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
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
Object를 이동시키는 여러가지 함수들
[Unity3D] 트랜스폼(Transform) 이동(Move)
유니티 좌표계 프로그램마다 사용하는 좌표계가 다릅니다. 따라서 좌표계에 대해서 이해하는 것은 매우 중요합니다. 유니티에서는 위치를 표현할 때 왼손 좌표계를 이용합니다. X축은 빨간색, Y
ssabi.tistory.com
'백지부터 시작하는 이세계 유니티 생활 since 2020' 카테고리의 다른 글
URP, Unity 2020.1.17 (0) | 2020.12.25 |
---|---|
Physics.OverlapSphere (0) | 2020.12.24 |
Sorting Layer (0) | 2020.12.24 |
Image property in Inspector (0) | 2020.12.14 |
Abstract (추상화), Interface (인터페이스) (0) | 2020.12.12 |