how to use movetowards in unity code example
Example 1: move towards target unity
private void Move(Vector3 target, float movementSpeed)
{
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
Example 2: unity movetowards
float speed;
Vector3 goalPosition;
void Update()
{
transform.position = Vector3.MoveTowards(transform.position, goalPosition, speed * Time.deltaTime);
}
Example 3: movetowards unity
void Update()
{
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
Example 4: how to move towards an object unity
Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)