My script does that when i collide with a special gameobject, the camera points at the enemy. It all works but the camera just looks directly at the enemy, and does not turn slowly. How do i make it turn smoothly ?
var target : Transform;
var distance = 3.0;
var height = 3.0;
var damping = 5.0;
var smoothRotation = true;
var rotationDamping = 10.0;
function Update ()
{
var wantedPosition = target.TransformPoint(0, height, -distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
if (smoothRotation) {
var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}
else transform.LookAt (target, target.up);
}
Oh it didn’t take my script with, here is the script that i made:
#pragma strict
var target : Transform;
var look : boolean = false;
function OnTriggerEnter (other : Collider) {
if(other.tag == “Wall”)
GameObject.Find( “First Person Controller” ).GetComponent(FPSInputController).enabled = false;
GameObject.Find( “First Person Controller” ).GetComponent(CharacterMotor).enabled = false;
GameObject.Find( “First Person Controller” ).GetComponent(MouseLook).enabled = false;
GameObject.Find( “Main Camera” ).GetComponent(MouseLook).enabled = false;
look = true;
yield(WaitForSeconds(5));
GameObject.Find( “First Person Controller” ).GetComponent(FPSInputController).enabled = true;
GameObject.Find( “First Person Controller” ).GetComponent(CharacterMotor).enabled = true;
GameObject.Find( “First Person Controller” ).GetComponent(MouseLook).enabled = true;
GameObject.Find( “Main Camera” ).GetComponent(MouseLook).enabled = true;
look = false;
}
function Update ()
{
if(look == true)
transform.LookAt(target);
}