Third Person Camera Movement control.

In third person controller, the camera movement and rotation based on character movement and rotation.When the character goes near to the wall and rotate in any of the direction,camera goes inside the wall.How to control my camera entering the wall or mesh.

You could use a raycast starting from the camera that tells it when there’s a wall nearby.

enter code hereFinally find the solution for avoiding Thirdperson camera entering the wall or mesh.Use Physics.Raycast to detect the object or wall opposite to Thirdperson.

Vector3 orgpos=new Vector3(0.0f,0.0f,0.0f);
	Vector3 objpos = transform.TransformPoint(0, height, -distance);
	Transform cameraTransform;
	void Update()
		RaycastHit hit;
		Vector3 back = transform.TransformDirection (-1 * Vector3.forward); 
		if (Physics.Raycast (transform.TransformPoint (orgpos), back, out hit, distance) && hit.transform != transform) {
			objpos.x = hit.point.x;
			objpos.z = hit.point.z;
			objpos.y = Mathf.Lerp (hit.point.y, objpos.y, Time.deltaTime);	
		cameraTransform.position = Vector3.Lerp (cameraTransform.position, objpos, Time.deltaTime);

Add the script to player and assign camera as target.