# How to use smoothly move camera to position using lerp?

So im trying to make a camera movement script for a simple RTS game im trying to make using vector3.lerp() but it doesn’t seem to be having any affect on my camera’s movement. the camera’s movement is still stiff. Is something wrong in this section of code?

``````if (Input.GetMouseButton(0))
{
float xinput = Input.GetAxisRaw("Mouse X");
float zinput = Input.GetAxisRaw("Mouse Y");
float x = trans.position.x;
float z = trans.position.z;
float y = trans.position.y;
Vector3 vec1 = trans.position;

Vector3 cam = trans.position = new Vector3(x + xinput, y, z + zinput);
trans.position = Vector3.Lerp(vec1, cam, 10);

}
``````

The third parameter of the Lerp method takes a percentage between the two vectors. It takes it as a value between 0 and 1 with 1 being 100 percent of the interpolation. The method clamps the third parameter to 1 so putting 10 in there is the same a putting 1 in there.
You could move the lerp outside of your if statement, like so;
private Vector3 _cam;

``````    public Transform Trans;

public float CamMoveSpeed = 5f;

private void Start()
{
_cam = Trans.position;
}

private void Update()
{
if (Input.GetMouseButton(0))
{
float xinput = Input.GetAxisRaw("Mouse X");
float zinput = Input.GetAxisRaw("Mouse Y");

float x = Trans.position.x;
float z = Trans.position.z;
float y = Trans.position.y;

_cam = new Vector3(x + xinput, y, z + zinput);
}

Trans.position = Vector3.Lerp(Trans.position, _cam, CamMoveSpeed * Time.deltaTime);
}
``````