Vetical lock camera look at?

So basically, i am working on a game that is on a 2d plane (like mk) but i need to have the camera locked to only move vertically (look up and down).

At the moment i am using the default look at script that comes with unity (shown below)

var target : Transform;
var damping = 6.0;
var smooth = true;

@script AddComponentMenu("Camera-Control/Smooth Look At")

function LateUpdate () {
	if (target) {
		if (smooth)
		{
			// Look at and dampen the rotation
			var rotation = Quaternion.LookRotation(target.position - transform.position);
			transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
		}
		else
		{
			// Just lookat
		    transform.LookAt(target);
		}
	}
}

function Start () {
	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

Can you help me out? Sorry, but i have a very limited knowledge of coding.

I have a good propos for you
add a varible like it
private Transform Transf;

at start write it

transf = new GameObject().transform;

at Update write it
transf.position = tranform.position;
tansf.lockat(target);

tranfsorm.eulerangle = new vector3(transf.eulerangle.x,0,trans.eulerangle.z)

or change it to your option

Sorry, can’t get this one working no matter how hard i try… :frowning:

MK meaning Mortal Kombat?

If that is your answer, no, you will never get that script to work. it uses rotation, you want position.

var target : Transform;
var damping : float = 6.0;
var smooth : boolean = true;
var offset : float = 10;
var yPos: float = 0;

function Start(){
	var targetPos : Vector3 = target.transform.position + Vector3.back * offset;
	targetPos.y = yPos;
	transform.position = targetPos;
}
function Update () {
	var targetPos : Vector3 = target.transform.position + Vector3.back * offset;
	targetPos.y = yPos;
	if(smooth){
		transform.position = Vector3.Slerp(transform.position, targetPos, Time.deltaTime * damping);
	}else{
		transform.position = targetPos;
	}
}

The concept is much the same as the rotational one, but it uses position instead.

Also, remove the component “Camera-Control/Smooth Look At” from your object as this doesn’t work with that.