make object move towards point unity code example
Example 1: how to make an object point towards the mouse in unity
Vector2 mousePosition = new Vector2 (
Input.GetAxis("MouseX"),
Input.GetAxis("MouseY")
);
transform.LookAt(mousePosition);
Example 2: move towards target unity
private void Move(Vector3 target, float movementSpeed)
{
transform.position += (target - transform.position).normalized * movementSpeed * 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)
Example 5: how to make an object move towards another in unity
transform.position = Vector3.MoveTowards(transform.position, taretPos, Qiaternion.identiy)