Lerp a MouseDrag for Camera Movement ?

Hello everyone,
I tried to achieve this for hours but still no result.
I would want to Lerp the movement of my camera, when I drag the map with the mouse.
For now I have this and it works well :

public void OnBeginDrag(PointerEventData eventData)
    {
        basePosition = new Vector3(eventData.pointerCurrentRaycast.worldPosition.x, eventData.pointerCurrentRaycast.worldPosition.z, 0);
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (eventData.pointerCurrentRaycast.gameObject == gameObject)
        {
            Vector3 currentPosition = new Vector3(eventData.pointerCurrentRaycast.worldPosition.x, eventData.pointerCurrentRaycast.worldPosition.z, 0);
            Vector3 delta = currentPosition - basePosition;
            cameraBase.Translate(-delta.x * dragSpeed, 0, -delta.y * dragSpeed);
        }
    }

The problem is, it seems a bit laggy especially when delta is big i.e the user moves his mouse quickly.
I checked the Stats and the game runs at 36-40 fps, which is enough for me.

I wondered if a Lerp could fix this, but I tried several implementations and none worked.
So I was thinking, what am I doing wrong ?
Is a Lerp really a solution ? What else is possible ?

I had in the first place a different implementation using Update or FixedUpdate, and Input.GetMouseButton, but there was in my opinion many inconvenients to that :

  • I wasn’t sure if it was efficient,
  • It was not mobile-compatible and I would have had to duplicate the code for mobile,
  • And it wasn’t really idiomatic given that there are OnBegin Drag and OnDrag functions that are supposed to achieve this.

So, thank you in advance for the replies and advices :slight_smile:

Up :slight_smile: