hello i would like for the camera to smooth follow on the z axis aswell as the other axises whilst looking at my spaceship from a certain distance. The other axis works fines but z is causing me difficulties
var target : Transform;
var distance = 5.0;
var height = 5.0;
var heightDamping = 2.0;
var rotationDamping = 3.0;
@script AddComponentMenu("Camera-Control/Smooth Follow")
function LateUpdate () {
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
var wantedRotationAngleY = target.eulerAngles.y;
var currentRotationAngleY = transform.eulerAngles.y;
var wantedRotationAngleX = target.eulerAngles.x;
var currentRotationAngleX = transform.eulerAngles.x;
var wantedRotationAngleZ = target.eulerAngles.z;
var currentRotationAngleZ = transform.eulerAngles.z;
// Damp the rotation around the y-axis
currentRotationAngleY = Mathf.LerpAngle (currentRotationAngleY, wantedRotationAngleY, rotationDamping * Time.deltaTime);
currentRotationAngleX = Mathf.LerpAngle (currentRotationAngleX, wantedRotationAngleX, rotationDamping * Time.deltaTime);
currentRotationAngleZ = Mathf.LerpAngle (currentRotationAngleZ, wantedRotationAngleZ, rotationDamping * Time.deltaTime);
// Damp the height
//currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler (currentRotationAngleX, currentRotationAngleY, currentRotationAngleZ);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.rotation= currentRotation ;
// Always look at the target
transform.LookAt (target);
}