unity – How to smoothly move in FixedUpdate using touches on mobile?

I have a serious issue for over a week now and no matter how – I can’t make it work.

I have a simple movement system, where I move the player on the X position:

private void Update()
{
    if (Input.touchCount > 0 &&
        Input.GetTouch(0).phase == TouchPhase.Moved)
    {
        Vector2 touchPos = Input.GetTouch(0).position;

        float normalizedX = touchPos.x / Screen.width;
     
        float xPos = Mathf.Lerp(-5f, 5f, normalizedX);

        transform.position = new Vector3(xPos * 3f, transform.position.y, transform.position.z);
    }

}

See the gif below. It works super smooth on a phone (the gif was taken on a pc, with a different script just to show you what I want to achieve so it laggs a bit). The input above works just by simply lerping the touch position.

enter image description here

I need to somehow to move it to FixedUpdate, because I will detect collisions and move the Rigidbody of the player with a constant speed on Z axis (forward). Also we will probably implement some jumps.

But I can’t do it. I tried basically everything:

  • moving on X in Update() and rb.MovePosition() in FixedUpdate() for Y & Z axes
  • tried various things in FixedUpdate(), I just can’t replicate it, because collecting the input in FixedUpdate gives incorrect results
  • tried to collect the input in Update and parse it in FixedUpdate, but it didn’t work (I probably did it incorrectly)

Im really out of clues, drives me crazy. It may be that Im overthinking it, thats why Im seeking for help here.

How to convert this simple movement system for a rigidbody.MovePosition() so it behaves identically as on the gif?