# How to make Touch Control Smooth

Hello there I really could use some help with this!

I have found this bit of code and it works perfectly with what I want to do, But when I Touch move the camera, it isnt smooth.

How would I be able to make the camera smoothly move when I use touch.

This is the code:

#pragma strict

var target : Transform; var distance = 20.0; var wheelSpeed = 10.0;
var xSpeed = 250.0; var ySpeed = 120.0;
var yMinLimit = -20; var yMaxLimit = 80;
var minDistance = 5.0;
var touch : Touch; var curDist = 0.0; var lastDist = 0.0; var pinchSpeed : float ; var cameraSpeed =1.0;
private var x = 0.0; private var y = 0.0;
function Start () {
var angles= transform.eulerAngles;

x = angles.y;
y = angles.x;

if (GetComponent.<Rigidbody>())
GetComponent.<Rigidbody>().freezeRotation = true;

}
function LateUpdate () {
if (target && GetComponent.<Camera>()) {
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
touch = Input.GetTouch(0);
x += touch.deltaPosition.x * xSpeed * 0.02f;
y -= touch.deltaPosition.y * ySpeed * 0.02f;
}

if (Input.touchCount > 1 && (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved))
{
var touch1 = Input.GetTouch(0);
var touch2 = Input.GetTouch(1);
curDist = Vector2.Distance(touch1.position, touch2.position);

if(curDist > lastDist)
{
distance += Vector2.Distance(touch1.deltaPosition, touch2.deltaPosition)*pinchSpeed/10;
}

else
{
distance -= Vector2.Distance(touch1.deltaPosition, touch2.deltaPosition)*pinchSpeed/10;
}
lastDist = curDist;
}

y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation= Quaternion.Euler(y, x, 0);
var vTemp = new Vector3(0.0f, 0.0f, -distance);
var position= rotation * vTemp + target.position;
transform.position = Vector3.Lerp (transform.position, position, cameraSpeed*Time.deltaTime);
transform.rotation = rotation;

}
}
static function ClampAngle (angle : float, min : float, max : float) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp (angle, min, max); }

Thank you, any help would be great!

You would need to use something like Lerp() to smoothen the camera position/angle over a given timeframe.