Follow Player in 2D Game

At present I am working on 2d side scrolling game.
I want camera follow for player movement only in horizontal movement. Right now I have written this type of target following script

public class SmoothFollow : MonoBehaviour
{
	public Transform target;
	public float smoothness = 10f;
	private Vector3 targetInitialPos;

	void OnEnable ()
	{
		target = null;
	}

	void Update ()
	{
		if (!target) {
			target = GameObject.Find ("MrJump").transform;
			targetInitialPos = target.position;
		} else {

			Vector3 cameraPosition = target.position - targetInitialPos;
			cameraPosition.y = 0f;
			cameraPosition.z = -10f;
//			transform.position = cameraPosition;
			transform.position = Vector3.Lerp (transform.position, cameraPosition, Time.deltaTime * smoothness);

		}
	}
}

If I directly apply cameraPosition to camera transform then it stuttering in mobile devices. So that I used lerp for this purpose but didn’t got success in that also.
I have attached small video also to represent my problem correctly.

Camera Stuttering Video

Using above code it shows jerky movement of camera. Not smoother one that I want. Please give some suggestion in this.

Ahhh, I had this problem too! But I found the solution but very sadly it was in 3d. But I may be able to help you. First make sure that the smooth follow target is the player. Second make sure the distance is 0 and that’s what helped me! Hope it helped you!

And if that doesn’t help than add mouse orbit. If your game is based on going upwards make sure that Max and Min x is 0 or if it is horizontal than make Max and Min y 0. Hope all my advice helped! :slight_smile: