move object to position unity code example
Example 1: movetowards unity
void Update()
{
transform.position += (target - transform.position).normalized * movementSpeed * Time.deltaTime;
}
Example 2: how to move towards an object unity
Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)
Example 3: unity how to move an object
float x = 10f;
float y = 10f;
float z = 10f;
Vector3 position = new Vector3(x, y, z);
transform.position = position;
Example 4: move gameobject to position unity
public Transform target;
public float speed;
void Update()
{
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}