Newer
Older
using UnityEngine;
using System.Collections;
public class SmootLookAtC : MonoBehaviour {
public Transform target;
public float damping = 6.0f;
public bool smooth = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void 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);
}
}
}
}