[SOLVED]Moving Rigidbody 2D on x axis at constant speed on mouse click

Hello dear gamedevs,

Keep in mind im pretty new into Unity and C# but basically what I’m asking is how you actually make a Rigidbody move at constant speed no matter where you click your mouse ? Heres what I’m trying to acomplish. Whenever you click on the screen my character will start walking to that position at the same speed no matter the distance bettween mouse click position and character current position.

I’ve tried MoveTowards but that obviously dont work for rigidbodies(unless im doing something terribly wrong?), so I came up with this little piece of code

void Update () {


        if (Input.GetMouseButtonDown(0))
        {
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            rb.velocity = (target - transform.position) * speed;

       
        }
    }

But the problem persists.

Thx!

Funny, 10 minutes after posting it I figured it myself,

heres the code in case any1 else would run into same

void Update () {


        if (Input.GetMouseButtonDown(0))
        {
           
            target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            //rb.velocity = (target - transform.position) * speed;
            target.z = transform.position.z;
            if(move == false)
            {
                move = true;
            }
          


       
        }
        if (move == true)
        {
            rb.MovePosition(Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime));
        }
    }

A question, why a rigidbody?
maybe is better this in if statement update:

transform.position = (transform.position - target.position).normalized * movingSpeed;

Depends of your project…
doing stuff with phisics is always better use it in FixedUpdate()