Touch camera controls

I am working to create a third person camera controls.
every thing working fine, but on first drag my camera snaps its rotation suddenly, after that it works smoothly untill pointer up event. then after next pointer down on drag it snaps again.
Can any one help on this.
below is my code.

using UnityEngine;
using UnityEngine.EventSystems;

public class CameraMobile2 : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
{
public float rotationSpeed;
private float xAxis;
private float yAxis;

private float minRotation = 10f;
private float maxRotation = 60f;

public Transform playerHead;
public Transform cameraTransform;
public RectTransform touchpadRect;

private bool isDragging = false;
private Vector2 lastDragPosition;

public void OnPointerDown(PointerEventData eventData)
{
isDragging = true;
lastDragPosition = eventData.position;
Debug.Log(“pointer Down”);
}

public void OnDrag(PointerEventData eventData)
{
Debug.Log(“pointer drag”);

if (!isDragging)
{
return;
}

Vector2 localPointerPosition;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(touchpadRect, eventData.position, null, out localPointerPosition))
{
Vector2 delta = localPointerPosition - lastDragPosition;
lastDragPosition = localPointerPosition;

yAxis += delta.x * rotationSpeed * Time.deltaTime;
xAxis -= delta.y * rotationSpeed * Time.deltaTime;
xAxis = Mathf.Clamp(xAxis, minRotation, maxRotation);

Vector3 targetRotation = new Vector3(xAxis, yAxis);

cameraTransform.eulerAngles = targetRotation;

}
}

public void OnPointerUp(PointerEventData eventData)
{
Debug.Log(“pointer Up”);

isDragging = false;

}
private void Update() {
cameraTransform.position = playerHead.position - cameraTransform.forward * 2f;

}
}

You changed localPointerPosition to the local point, but you didn’t do the same for lastDragPosition, so your delta doesn’t start at 0.

Please edit your post to use code-tags when posting code.

Thanks.

Thanks alot. It took some time for me to understand but it worked finally.