i have a top view game and i need the camera to follow the player with rotation in the x- axis so it only goes left and right to look at the player at the current time it will turn itself so the bottom of the camera is always facing him i need it to be the left or the right side.
i also need my camera to move along its x axis with restictions say 10 across and - 10 the other way no y or z axis
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;
}
I had similar problem and here is simple Java script I come up with for my solution.
After you attach this script to your camera then click on Camera and in Inspector drop your player into camera script where it asks for Target.
MAKE SURE that your camera Y rotation is correct (I needed it at 180) and your Z position is correct (I needed it at 17 because my floor is at 0 and I needed for it to be far enough so that all my objects are in its range)
I hope this will help you and others.
var target : Transform;
function Update ()
{
transform.eulerAngles = Vector3(0, 180, 0);
transform.position = Vector3(target.transform.position.x, 0, 17);
}