Camera (mouse orbit), linecast and shakiness

I made a collision manager for MouseOrbitImproved.cs and everything is working as intended, excepted that it constantly goes slighty back and forth.

Since I am using very small units it looks like a regular shaking.

Here is the code of my collision manager:

Vector3 lineBack = new Vector3 (transform.position.x, transform.position.y, transform.position.z - 0.1f); // I take camera's position and check slighty behind its current distance
			if (Physics.Linecast(target.position,transform.position,layerMask))
				distance = Mathf.Lerp(distance, distanceMin, Time.deltaTime * 3.0f);
			else if (distance < distanceMax && !Physics.Linecast(target.position,lineBack,layerMask)
				distance = Mathf.Lerp(distance, distance + 0.1f, Time.deltaTime * 1.5f);

How do you think I should change this to prevent this problem happening?

Nailed this one!

I add the character controller of my player object and then check its velocity before applying any recoil for the camera:

Vector3 lineBack = new Vector3 (transform.position.x, transform.position.y, transform.position.z - 0.1f);
			if (Physics.Linecast(target.position,transform.position,layerMask))
				distance = Mathf.Lerp(distance, distanceMin, Time.deltaTime * 3.0f);
			else if (distance < distanceMax && !Physics.Linecast(target.position,lineBack,layerMask) && playerController.velocity != Vector3.zero) // there it is!
				distance = Mathf.Lerp(distance, distance + 0.1f, Time.deltaTime * 1.5f);

This way it doesn’t recoil when the character is immobile. Since the problem only appears when that’s the case, it does the trick.

PS: it’s the second time I ask something there and then reply to myself. I guess it’s how my cognitive processes are built, heh. Regardless, I hope it may be helpful to anyone else and I’d be happy to read alternatives ideas.