Translate camera from one position back to its original position

So I am making a space game and I wrote a script for the camera to be in one position, and when the scroll wheel is pushed down, you can orbit the camera around the ship. The problem I am having is getting the camera to go back behind the ship. This is my script:

    float rspeed = 2.5F;
    bool move = false;
    public Transform target;
	public Transform camsp;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update ()
    {
        if (Input.GetMouseButton(2))
        {
            float rotx = Input.GetAxis("Mouse X") * rspeed;
            float roty = Input.GetAxis("Mouse Y") * rspeed;
            transform.RotateAround(target.position, target.up, rotx);
            transform.RotateAround(target.position, target.right, roty);
        }
        if(Input.GetMouseButtonUp(2))
        {
            //sp = transform.position;
            move = true;

        }
        if (move == true)
        {
			transform.position = new Vector3(Mathf.Lerp(transform.position.x, camsp.transform.position.x, Time.deltaTime), Mathf.Lerp(transform.position.y, camsp.transform.position.y, Time.deltaTime), Mathf.Lerp(transform.position.z, camsp.transform.position.z, Time.deltaTime));
			transform.LookAt(target);

        }

I don’t know how to stop this. I tried this:

if(transform.position == camsp.position)
{
      move = false;
}

but it doens’t work. any ideas how to fix this?

Try this…

if(move)
   transform.position = Vector3.Lerp(transform.position, camps.transform.position);

if(Vector3.Distance(transform.position, camps.transform.position)< .005f)
   move=false;

Sometimes the Vectors never get to their original position because of other movement within the scene. I do have a question of whether or not “camps” is a child of the “target” gameObject and if any of them are moving around. If so, you might wanna try “transform.localPosition” instead of “transform.position”. Since it’s a camera location you’re playing with and it is following anther gameobject, there may be differences in global and local positions.