Object follows touch.position

The point of our script is for the ball to follow our finger when placed on the screen but since its following where ever we place our finger it will teleport to any new location instead of just smoothly going to where are finger is. The code does work, however it follows our finger but every time i release my finger and put it back down it will teleport to that new position. I don’t know how to fix it, I’m a beginner.
This is for a 2D game
This is my code:

    void Update () {
        if (Input.touchCount > 0) {
            // The screen has been touched so store the touch
            Touch touch = Input.GetTouch (0);

            if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
                Vector3 touchPosition = Camera.main.ScreenToWorldPoint (new Vector3 (touch.position.x, touch.position.y, 10));             
                transform.position = touchPosition;
            }

            }
        }

Yesterday the OP had the same question, and I tried answering: How to stop object from teleporting with the touch drag function

Please follow up in that thread if you got stuck or didn’t understand something. :slight_smile:

1 Like