Camera following an object...

How can I use parenting (or scripting) to allow a camera to follow an object along the x axis only?

Hey! I have a simple code that can help you. Is very simple:

#pragma strict

var myCamera : Transform;
var target : Transform;

function Update () 
{
	myCamera.position = target.position + Vector3(0, 10, 0);
}

Then you have to attach it to whatever gameObject and assign myCamera to your camera and target to your target ^^

Well. if you want the camera to follow the object make the camera a child of the object, and position/rotate it to look at the object..

If you want a smooth version in script do something like this:

var target : Transform;
var smooth : float = 5;
function Update () {
    transform.position.x = Mathf.Lerp(transform.position.x,target.position.x,Time.deltaTime*smooth);
    transform.position.y = Mathf.Lerp(transform.position.y,target.position.y,Time.deltaTime*smooth);

}

Attach that script to the camera and set target to be the object the camera follows.

you can remove the line where it says transform.position.y == ect to stop it following the y axis...

Hope this helps!

how could i assign them?