im working on a space shooter and bumped into a little problem... im using a script to control my camera movement but it always stays at the same height. i don't know how to add height to this script. i hope someone can help me with this problem.
here's the script im using:
var target : Transform;
var distanceToFollow : float = 5.0;
var height : float = 1.0;
var moveSpeed : float = 1.0;
var rotationSpeed : float = 0.2;
var damping = 6.0;
var smooth = true;
private var targetRay : Ray;
@script AddComponentMenu("Camera-Control/Smooth Look At")
function Update () {
targetRay = new Ray(target.position,-target.forward);
point = targetRay.GetPoint(distanceToFollow);
point = Vector3.Slerp(transform.position, point, Time.deltaTime * moveSpeed);
transform.position = point;
transform.LookAt(target,target.up);
}
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;
}
'