recover the position after camera collision

Hi , I was trying to add collision to my camera and keep the custom zoom distance afther the collision, my code detect the collision with raycast and make the zoom but don’t recover the position, any help will be appreciated .
My code so far:

using UnityEngine;
using System.Collections;


	public class CameraClassic : MonoBehaviour {
		public Transform target;

		[System.Serializable]
		public class PositionSettings
		{
			public Vector3 targetPosOffset = new Vector3 (0, 3.4f,0);
			public float  lookSmooth = 100f;
			public float distancefromtarget = -8;
			public float zoomSmooth = 10;
			public float maxZoom = -2;
			public float minZoom = -15;

		}
		[System.Serializable]
		public class OrbitSettings
		{
			public float xRotation = -20;
			public float yRotation = -180;
			public float maxXRotation = 1;
			public float minXRotation = -85;
			public float vorbitSmooth = 150;
			public float horbitSmooth = 150;
		}

		
		[System.Serializable]
		public class InputSettings
		{

			public string ORBIT_HORIZONTAL_SNAP = "OrbitHorizontalSnap";
			public string ORBIT_HORIZONTAL = "OrbitHorizontal";
			public string ORBIT_VERTICAL = "OrbitVertical";
			public string ZOOM = "Mouse ScrollWheel";
		}
		public PositionSettings position = new PositionSettings();
		public OrbitSettings orbit = new OrbitSettings ();
		public InputSettings input = new InputSettings ();
	public RaycastHit WallHit;
		Vector3 targetPos = Vector3.zero;
		Vector3 destination = Vector3.zero;

		CharacterController charController;
		float vOrbitInput, hOrbitInput, zoomInput, hOrbitSnapInput;



		void start()
		{


			SetCameraTarget(target);
			vOrbitInput = hOrbitInput = zoomInput = hOrbitSnapInput = 0;


			moveToTarget();//new

		}
		void Update()
		{
			GetInput ();
			OrbitTarget ();
		Debug.DrawLine ( destination, target.position, Color.cyan);
		RaycastHit WallHit = new RaycastHit ();

			ZoomInOnTarget ();


		}
		void LateUpdate()
		{


			moveToTarget ();
			lookAtTarget ();

		}
		void SetCameraTarget (Transform t)
		{

			target = t;
			if (target != null)
			{
				if (target.GetComponent<CharacterController> ())
				{
					charController = target.GetComponent<CharacterController> ();

				}
				else
					Debug.LogError ("the camera's target needs a character controller.");
			}
			else
				Debug.LogError("Your camera needs a target.");

		}


		void moveToTarget()
		{
			targetPos = target.position + position.targetPosOffset;
			destination = Quaternion.Euler(orbit.xRotation, orbit.yRotation + target.eulerAngles.y, 0) * -Vector3.forward * position.distancefromtarget;
			destination += targetPos;
			transform.position = destination;

			{

			}

		}

		void lookAtTarget()

		{
			Quaternion targetRotation = Quaternion.LookRotation(targetPos - transform.position);
			transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, position.lookSmooth * Time.deltaTime);


		}
		void GetInput()
		{

			vOrbitInput = Input.GetAxis (input.ORBIT_VERTICAL);
			hOrbitInput = Input.GetAxis (input.ORBIT_HORIZONTAL);
			hOrbitSnapInput = Input.GetAxis (input.ORBIT_HORIZONTAL_SNAP);
			zoomInput = Input.GetAxis (input.ZOOM);
			
		}

		void OrbitTarget()
		{
			if (hOrbitSnapInput > 0)
			{
				orbit.yRotation = -180;
			}
			orbit.xRotation += -vOrbitInput * orbit.vorbitSmooth * Time.deltaTime;
			orbit.yRotation += -hOrbitInput * orbit.vorbitSmooth * Time.deltaTime;
			if (orbit.xRotation > orbit.maxXRotation)
			{
				orbit.xRotation = orbit.maxXRotation;
			}
			if (orbit.xRotation < orbit.minXRotation)
			{
				orbit.xRotation = orbit.minXRotation;
			}
		}
	void ZoomInOnTarget(){
		
		position.distancefromtarget += zoomInput * position.zoomSmooth;
			if (Physics.Linecast (destination, target.position, out WallHit)) { 


				if (WallHit.collider.CompareTag ("Terrain")) {
				
					print ("collision");
					position.distancefromtarget = (WallHit.point.y);

				}  

			}

		
			
			if (position.distancefromtarget > position.maxZoom) {
				position.distancefromtarget = position.maxZoom;
			}
			if (position.distancefromtarget < position.minZoom) {
				position.distancefromtarget = position.minZoom;
			}
		}

	}

I’ll answer myself:

using UnityEngine;
using System.Collections;


	public class ClassicView : MonoBehaviour {
		public Transform target;

		[System.Serializable]
		public class PositionSettings
		{
			public Vector3 targetPosOffset = new Vector3 (0, 3.4f,0);
			public float  lookSmooth = 100f;
			public float distancefromtarget = -8;
			public float zoomSmooth = 10;
			public float maxZoom = -2;
			public float minZoom = -15;

		}
		[System.Serializable]
		public class OrbitSettings
		{
			public float xRotation = -20;
			public float yRotation = -180;
			public float maxXRotation = 1;
			public float minXRotation = -85;
			public float vorbitSmooth = 150;
			public float horbitSmooth = 150;
		}

		
		[System.Serializable]
		public class InputSettings
		{

			public string ORBIT_HORIZONTAL_SNAP = "OrbitHorizontalSnap";
			public string ORBIT_HORIZONTAL = "OrbitHorizontal";
			public string ORBIT_VERTICAL = "OrbitVertical";
			public string ZOOM = "Mouse ScrollWheel";
		}
		public PositionSettings position = new PositionSettings();
		public OrbitSettings orbit = new OrbitSettings ();
		public InputSettings input = new InputSettings ();
		public RaycastHit hit;
		Vector3 targetPos = Vector3.zero;
		Vector3 destination = Vector3.zero;
		Vector3 detector ;
		CharacterController charController;
		float vOrbitInput, hOrbitInput, zoomInput, hOrbitSnapInput;



		void start()
		{


			SetCameraTarget(target);
			vOrbitInput = hOrbitInput = zoomInput = hOrbitSnapInput = 0;


			moveToTarget();//new

		}
		void Update()
		{
			GetInput ();
			OrbitTarget ();


			ZoomInOnTarget ();


		}
		void LateUpdate()
		{


			moveToTarget ();
			lookAtTarget ();

		}
		void SetCameraTarget (Transform t)
		{

			target = t;
			if (target != null)
			{
				if (target.GetComponent<CharacterController> ())
				{
					charController = target.GetComponent<CharacterController> ();

				}
				else
					Debug.LogError ("the camera's target needs a character controller.");
			}
			else
				Debug.LogError("Your camera needs a target.");

		}


		void moveToTarget()
	{
		targetPos = target.position + position.targetPosOffset;
		detector = Quaternion.Euler(orbit.xRotation, orbit.yRotation + target.eulerAngles.y, 0) * -Vector3.forward * position.minZoom;
		detector += targetPos;
		if (Physics.Raycast ( targetPos,detector, out hit)) 
		{
			if (hit.collider.CompareTag ("Terrain")) 
			{
				if (hit.distance > position.distancefromtarget) 
				{
					Debug.LogError ("wall");
					destination = Quaternion.Euler (orbit.xRotation, orbit.yRotation + target.eulerAngles.y, 0) * Vector3.forward * hit.distance/4f;
					destination += targetPos;
					transform.position = destination;

				}
			}
			else 
			{

				destination = Quaternion.Euler (orbit.xRotation, orbit.yRotation + target.eulerAngles.y, 0) * -Vector3.forward * position.distancefromtarget;
				destination += targetPos;
				transform.position = destination;
			}
		}
	}


		void lookAtTarget()

		{
			Quaternion targetRotation = Quaternion.LookRotation(targetPos - transform.position);
			transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, position.lookSmooth * Time.deltaTime);


		}
		void GetInput()
		{

			vOrbitInput = Input.GetAxis (input.ORBIT_VERTICAL);
			hOrbitInput = Input.GetAxis (input.ORBIT_HORIZONTAL);
			hOrbitSnapInput = Input.GetAxis (input.ORBIT_HORIZONTAL_SNAP);
			zoomInput = Input.GetAxis (input.ZOOM);
			
		}

		void OrbitTarget()
		{
			if (hOrbitSnapInput > 0)
			{
				orbit.yRotation = -180;
			}
			orbit.xRotation += -vOrbitInput * orbit.vorbitSmooth * Time.deltaTime;
			orbit.yRotation += -hOrbitInput * orbit.vorbitSmooth * Time.deltaTime;
			if (orbit.xRotation > orbit.maxXRotation)
			{
				orbit.xRotation = orbit.maxXRotation;
			}
			if (orbit.xRotation < orbit.minXRotation)
			{
				orbit.xRotation = orbit.minXRotation;
			}
		}
	void ZoomInOnTarget(){
		
		position.distancefromtarget += zoomInput * position.zoomSmooth;


		
			
			if (position.distancefromtarget > position.maxZoom) {
				position.distancefromtarget = position.maxZoom;
			}
			if (position.distancefromtarget < position.minZoom) {
				position.distancefromtarget = position.minZoom;
			}
		}

	}