# Move object towards the center of coordinating system

I would like to move a object towards Vector2(0, 0), but every time I use this script, the object always goes down, instead of going towards the center of the coordinate system.

        void Update()
{
//Object rotation
if (!Input.GetMouseButtonDown(0))
{
_angle += speed * Time.deltaTime;
var offset = new Vector2(Mathf.Sin(_angle), Mathf.Cos(_angle)) * radius;
transform.position = _centre + offset;
} else
{
//Moving object towards center
rb.transform.position = Vector2.MoveTowards(transform.position, Vector2.zero, speed * Time.deltaTime);
}


• Did you try the solution? Because I have directly copied and pasted your code, only switched _centre with Vector2.zero and if I don't set the rigidbody to kinematic, it starts to fall down on Y-Axis. But when I set the body to kinematic, it starts to move towards center. Try to change the GetMouseButtonDown(0) to GetMouseButton(0) to see the effect clearly. Jun 3 '17 at 18:36
• You can use a trigger collider and surround the movement code with a boolean flag. And inside the OnTriggerEnter2D() function, set that boolean to false inorder to cancel movement. Jun 3 '17 at 23:31