2D, lock the "y" axis

Hello, I was wondering how can I look the camera in the “y” axis in order for my camera to only follow my character on the “horizontal axis”. How can I do this? Just like super mario, where the camera follows Mario while moving forwards and backwards but never when he jumps.

Thanks! :smiley:

Hello,

you need to write custom follow script for your camera. Basic implementation can look like this.

public class FollowScript : MonoBehaviour
{
	public Transform FollowObject;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update ()
	{
		Vector3 pos = new Vector3(FollowObject.position.x, transform.position.y, transform.position.z);
		transform.position = pos;
	}
}

You need to attach script to camera, drag and drop your character game object to FollowObject property and make sure camera is not child of character in Hierarchy window.

You will need to add more code to update function, like offsetting, smoothing etc. to have it look really good, but this is basic idea behind camera control.