Object moving even after I'm not touching the screen

I’m new to this thread and unity, so sorry if this is in the wrong section or if my question is very obvious.

I have started to make a space shooter game in unity 2d for android. I’ve made my ship move right and left, when touching the right side or the left side of the screen respectively (The rigidbody2d is kinematic, hence why I’m using moveposition). However, when I press the screen and let go, the object does not stop moving until a few moments later.

Here is the code that i have used:

private Rigidbody2D rb2d;

public float moveRate = 0.1f;
void Start () {
    rb2d = GetComponent<Rigidbody2D> ();
}
   
void Update () {
    foreach (Touch touch in Input.touches) {
        if (touch.position.x < Screen.width/2) {
            rb2d.MovePosition(rb2d.position - new Vector2(moveRate, 0) * Time.fixedDeltaTime);
        }
        else if (touch.position.x > Screen.width/2) {
            rb2d.MovePosition(rb2d.position + new Vector2(moveRate, 0) * Time.fixedDeltaTime);
        }
    }
}

I see some mixing between Update() and fixedDeltaTime, which will cause unpredictable behavior.

Since you’re moving a Rigidbody2D, move your code block to FixedUpdate() rather than Update() (check out the documentation for Rigidbody2D.MovePosition() to see why this is-- generally speaking, do Rigidbody updates in FixedUpdate() ).

For future reference, for non-physics transient behaviors like fading in a camera, you can use Time.deltaTime for the time between Update()'s.

Another note: You may want to use your foreach block to take the mean value of the positions of all of the touches. As it is, your game will just use the last touch in Input.touches, and after you move it to FixedUpdate(), it may cause problems with the movement speed. Just something to double-check.