I have a sprite in a 2d mobile game in unity and I am trying to touch and drag that sprite with my finger so the sprite should move exactly where the finger is touched on the screen. But the problem is the sprite always lags behind where the finger is on the screen, when I move the finger at very fast speeds, the sprite is delayed. The sprite shall be very immediate in its movement and be present at the point on screen wherever the finger is touched (the sprite will be dragged by the finger touch) at all times, it is very crucial for the game.
I have tried below code:
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
touchPosition.z = 0f;
if (touch.phase == TouchPhase.Began)
{
touchOffset = transform.position - touchPosition;
}
transform.position = touchPosition + touchOffset;
}
}
With this, the sprite has a delay at very fast speeds of finger touch and drag. The speed is very crucial for the game and the sprite should always be present where the finger is touched on the screen.